internal static IVsDataConnectionProperties GetConnectionProperties( IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } IVsDataConnectionProperties properties = null; var provider = GetVsProvider(dataProviderManager, dataConnection); Debug.Assert(provider != null, "null provider value for dataConnection"); if (provider != null) { var dataSource = GetVsDataSource(dataProviderManager, dataConnection); properties = provider.TryCreateObject <IVsDataConnectionProperties>(dataSource); Debug.Assert(properties != null, "Could not get connection properties service"); if (properties != null) { var connectionString = DecryptConnectionString(dataConnection) ?? string.Empty; properties.Parse(connectionString); } } return(properties); }
public DataSourceComboBoxItem(string displayName, IVsDataConnection connection) { Debug.Assert(null != connection, "connection should not be null"); _displayName = displayName; _dataConnection = connection; }
private void SetDataConnection(IVsDataConnection dataConnection) { Debug.Assert(dataConnection != null, "should not be called with null dataConnection"); _dataConnection = dataConnection; textBoxConnectionString.Text = GetTextBoxConnectionStringValue( _dataProviderManager, _dataConnection.Provider, _dataConnection.DisplayConnectionString); textBoxAppConfigConnectionName.Text = ModelBuilderWizardForm.WizardMode.PerformAllFunctionality == Wizard.Mode ? GetDefaultAppConfigEntryName(_dataConnection) : Wizard.ModelBuilderSettings.AppConfigConnectionPropertyName; if (ContainsSensitiveData(_dataConnection)) { sensitiveInfoTextBox.Enabled = true; allowSensitiveInfoButton.Checked = false; allowSensitiveInfoButton.Enabled = true; disallowSensitiveInfoButton.Checked = false; disallowSensitiveInfoButton.Enabled = true; } else { sensitiveInfoTextBox.Enabled = false; allowSensitiveInfoButton.Checked = false; allowSensitiveInfoButton.Enabled = false; disallowSensitiveInfoButton.Checked = false; disallowSensitiveInfoButton.Enabled = false; } }
private DatabaseInfo GetDatabaseInfo(IVsDataConnection dialogResult, string connectionString) { var dbType = DatabaseType.SQLCE35; var providerInvariant = "N/A"; // Find connection string and provider var connection = (DbConnection)dialogResult.GetLockedProviderObject(); var providerManager = (IVsDataProviderManager)Package.GetGlobalService(typeof(IVsDataProviderManager)); IVsDataProvider dp; providerManager.Providers.TryGetValue(dialogResult.Provider, out dp); if (dp != null) { providerInvariant = (string)dp.GetProperty("InvariantName"); dbType = DatabaseType.SQLCE35; if (providerInvariant == "System.Data.SqlServerCe.4.0") { dbType = DatabaseType.SQLCE40; } if (providerInvariant == "System.Data.SQLite.EF6") { dbType = DatabaseType.SQLite; } if (providerInvariant == "System.Data.SqlClient") { dbType = DatabaseType.SQLServer; } } return(new DatabaseInfo { DatabaseType = dbType, ConnectionString = connectionString, ServerVersion = providerInvariant }); }
public void ResetDataConnection(IVsDataConnection dataConnection) { // do not need to reset _provider or _isConnectionStringEncrypted since these are the same // as original connection Debug.Assert(null != dataConnection, "dataConnection should not be null"); _dataConnection = dataConnection; }
internal static IVsDataConnection GetDataConnection( IVsDataConnectionManager dataConnectionManager, IVsDataProviderManager dataProviderManager, string providerInvariantName, string providerConnectionString) { IVsDataConnection connection = null; var dataProviderGuid = Guid.Empty; foreach (var dataProvider in dataProviderManager.Providers.Values) { var invariantName = dataProvider.GetProperty("InvariantName") as string; if (!string.IsNullOrEmpty(invariantName) && invariantName == providerInvariantName) { dataProviderGuid = dataProvider.Guid; break; } } Debug.Assert(dataProviderGuid != Guid.Empty, "The IVsDataProvider could not be found among the list of providers"); if (dataProviderGuid != Guid.Empty) { connection = dataConnectionManager.GetConnection(dataProviderGuid, providerConnectionString, false); } return(connection); }
public void Connect(IVsDataConnection connection) { if (connection == null) { throw new ArgumentNullException("connection"); } connection.Open(); }
private string GetDefaultAppConfigEntryName(IVsDataConnection dataConnection) { // get the initial catalog string from the connection var initialCatalog = DataConnectionUtils.GetInitialCatalog(_dataProviderManager, dataConnection); Wizard.ModelBuilderSettings.InitialCatalog = initialCatalog; // compute the connection string name return(Wizard.GetUniqueConnectionStringName(initialCatalog)); }
public IVsDataConnection GetDataConnection(IVsDataConnectionManager dataConnectionManager) { if (null == _dataConnection) { Debug.Assert(null != dataConnectionManager, "dataConnectionManager should not be null"); _dataConnection = dataConnectionManager.GetConnection(_provider, _connectionString, _isConnectionStringEncrypted); } return(_dataConnection); }
internal static void RemoveDataConnection(EFCorePowerToolsPackage package, IVsDataConnection dataConnection) { var dataExplorerConnectionManager = package.GetService <IVsDataExplorerConnectionManager>(); foreach (var connection in dataExplorerConnectionManager.Connections.Values) { if (connection.Connection == dataConnection) { dataExplorerConnectionManager.RemoveConnection(connection); } } }
public DataSchemaServer(IVsDataConnection connection) { if (connection == null) { throw new ArgumentNullException("connection"); } _connection = connection; _selector = (connection).GetService(typeof(IVsDataMappedObjectSelector)) as IVsDataMappedObjectSelector; if (_selector == null) { throw new ArgumentException("IVsDataMappedObjectSelector"); } }
public DataSchemaServer(IVsDataConnection connection) { if (connection == null) { throw new ArgumentNullException("connection"); } _connection = connection; _selector = (connection).GetService(typeof(IVsDataMappedObjectSelector)) as IVsDataMappedObjectSelector; if (_selector == null) { throw new ArgumentException("IVsDataMappedObjectSelector"); } }
private string GetDefaultAppConfigEntryName(IVsDataConnection dataConnection) { // get the initial catalog string from the connection var initialCatalog = DataConnectionUtils.GetInitialCatalog(_dataProviderManager, dataConnection); Wizard.ModelBuilderSettings.InitialCatalog = initialCatalog; // compute the connection string name return(ConnectionManager.GetUniqueConnectionStringName( _configFileUtils, Wizard.ModelBuilderSettings.GenerationOption == ModelGenerationOption.CodeFirstFromDatabase ? Wizard.ModelBuilderSettings.ModelName : GetBaseEdmxConnectionStringName(initialCatalog))); }
private static bool ContainsSensitiveData(IVsDataConnection dataConnection) { if (dataConnection == null) { return(false); } // need to compare ignoring case as DecryptConnectionString() can turn e.g. 'Integrated Security' into 'integrated security' else if (dataConnection.DisplayConnectionString.Equals( DataConnectionUtils.DecryptConnectionString(dataConnection), StringComparison.CurrentCultureIgnoreCase)) { return(false); } else { return(true); } }
private static Guid GetVsDataSource(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } var guid = Guid.Empty; var provider = GetVsProvider(dataProviderManager, dataConnection); guid = provider.DeriveSource(DataProtection.DecryptString(dataConnection.EncryptedConnectionString)); return guid; }
internal static string DecryptConnectionString(IVsDataConnection dataConnection) { return dataConnection == null ? string.Empty : DataProtection.DecryptString(dataConnection.EncryptedConnectionString); }
internal DataSource( string displayName, IVsDataConnection dataConnection ) : this( displayName, new Lazy<IVsDataConnection>( () => dataConnection ) ) { Contract.Requires( !string.IsNullOrEmpty( displayName ) ); }
public IVsDataConnection GetDataConnection(IVsDataConnectionManager dataConnectionManager) { if (null == _dataConnection) { Debug.Assert(null != dataConnectionManager, "dataConnectionManager should not be null"); _dataConnection = dataConnectionManager.GetConnection(_provider, _connectionString, _isConnectionStringEncrypted); } return _dataConnection; }
private void SetDataConnection(IVsDataConnection dataConnection) { Debug.Assert(dataConnection != null, "should not be called with null dataConnection"); _dataConnection = dataConnection; textBoxConnectionString.Text = GetTextBoxConnectionStringValue( _dataProviderManager, _dataConnection.Provider, _dataConnection.DisplayConnectionString); textBoxAppConfigConnectionName.Text = ModelBuilderWizardForm.WizardMode.PerformAllFunctionality == Wizard.Mode ? GetDefaultAppConfigEntryName(_dataConnection) : Wizard.ModelBuilderSettings.AppConfigConnectionPropertyName; if (ContainsSensitiveData(_dataConnection)) { sensitiveInfoTextBox.Enabled = true; allowSensitiveInfoButton.Checked = false; allowSensitiveInfoButton.Enabled = true; disallowSensitiveInfoButton.Checked = false; disallowSensitiveInfoButton.Enabled = true; } else { sensitiveInfoTextBox.Enabled = false; allowSensitiveInfoButton.Checked = false; allowSensitiveInfoButton.Enabled = false; disallowSensitiveInfoButton.Checked = false; disallowSensitiveInfoButton.Enabled = false; } }
private static bool ContainsSensitiveData(IVsDataConnection dataConnection) { if (dataConnection == null) { return false; } // need to compare ignoring case as DecryptConnectionString() can turn e.g. 'Integrated Security' into 'integrated security' else if (dataConnection.DisplayConnectionString.Equals( DataConnectionUtils.DecryptConnectionString(dataConnection), StringComparison.CurrentCultureIgnoreCase)) { return false; } else { return true; } }
void IVisualStudioAccess.RemoveDatabaseConnection(IVsDataConnection dataConnection) { VsDataHelper.RemoveDataConnection(_package, dataConnection); }
private void OnWorkCompleted(object sender, RunWorkerCompletedEventArgs e) { _isWorkerRunning = false; SetDoWorkState(false); try { if (e.Error != null) { if (CriticalException.IsCriticalException(e.Error)) { throw e.Error; } var errMsgWithInnerExceptions = VsUtils.ConstructInnerExceptionErrorMessage(e.Error); var errMsg = string.Format( CultureInfo.CurrentCulture, DialogsResource.NewFunctionImportDialog_GetColumnInfoException , e.Error.GetType().FullName, errMsgWithInnerExceptions); detectErrorLabel.Text = errMsg; returnTypeShapeTabControl.SelectedTab = detectErrorTabPage; } else if (!e.Cancelled) { var schemaProcedure = e.Result as IDataSchemaProcedure; if (schemaProcedure == null) { Debug.Assert( Function != null, "this.Function should not be null. If it is null then 'Get Columns Information' button should be disabled which should stop you getting to here."); var sprocName = (Function == null ? string.Empty : (DatabaseObject.CreateFromFunction(Function).ToString())); detectErrorLabel.Text = string.Format( CultureInfo.CurrentCulture, DialogsResource.NewFunctionImportDialog_CouldNotFindStoredProcedure, sprocName); returnTypeShapeTabControl.SelectedTab = detectErrorTabPage; } else { // regardless of whether it's a stored proc or a function... if (schemaProcedure.Columns != null) { if (UpdateComplexTypeList(schemaProcedure.Columns)) { Schema = schemaProcedure; UpdateReturnTypeListState(IsResultTypeAvailable); returnTypeShapeListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); returnTypeShapeListView.Items[0].Selected = true; } else { detectErrorLabel.Text = DialogsResource.NewFunctionImportDialog_NoColumnsReturned; returnTypeShapeTabControl.SelectedTab = detectErrorTabPage; } } } } } finally { if (_openedDbConnection != null) { _openedDbConnection.Close(); _openedDbConnection = null; } } if (GetResultColumnsCompletedEventStorage != null) { GetResultColumnsCompletedEventStorage(this, EventArgs.Empty); } }
public SchemaSelector(IVsDataConnection connection) : base(connection) { }
public SqliteSourceInformation(IVsDataConnection connection) : base(connection) { }
public DataSourceSelector(IVsDataConnection connection) : base(connection) { }
public SqliteMappedObjectConverter(IVsDataConnection connection) : base(connection) { }
private void OnDispose(bool disposing) { Debug.Assert( _openedDbConnection == null, "There is still open DBConnection when NewFunctionImportDialog is closing."); if (_openedDbConnection != null) { _openedDbConnection.Close(); _openedDbConnection = null; } }
public VfpDSRefBuilder(IVsDataConnection connection) : base(connection) { }
internal static void PopulateNewFunctionSchemaProcedures( Dictionary <EntityStoreSchemaFilterEntry, IDataSchemaProcedure> newFunctionSchemaProcedureMap, string designTimeProviderInvariantName, string designTimeProviderConnectionString, DoWorkEventArgs e = null, BackgroundWorker worker = null, int startingAmountOfProgressBar = 0, int amountOfProgressBarGiven = 100) { // set up database connection var dataConnectionManager = Services.ServiceProvider.GetService(typeof(IVsDataConnectionManager)) as IVsDataConnectionManager; Debug.Assert(dataConnectionManager != null, "Could not find IVsDataConnectionManager"); var dataProviderManager = Services.ServiceProvider.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; Debug.Assert(dataProviderManager != null, "Could not find IVsDataProviderManager"); IVsDataConnection dataConnection = null; if (null != dataConnectionManager && null != dataProviderManager) { dataConnection = DataConnectionUtils.GetDataConnection( dataConnectionManager, dataProviderManager, designTimeProviderInvariantName, designTimeProviderConnectionString); } if (null == dataConnection) { throw new ProgressDialogException( string.Format( CultureInfo.CurrentCulture, Design.Resources.RetrievingSprocReturnTypeErrorMessage, "null IVsDataConnection")); } // open the database connection and collect info for each Function try { dataConnection.Open(); var dataSchemaServer = new DataSchemaServer(dataConnection); // now loop over all entries adding return type information var numFunctionFilterEntries = newFunctionSchemaProcedureMap.Count; var numFunctionFilterEntryCurrent = 0; foreach (var entry in newFunctionSchemaProcedureMap.Keys.ToList()) { numFunctionFilterEntryCurrent++; if (worker != null && e != null && worker.CancellationPending) { // user requested interrupt of this process e.Cancel = true; } else { if (worker != null && worker.WorkerReportsProgress) { // report progress so ProgressDialog can update its status var percentCompleted = startingAmountOfProgressBar + ((int) (((numFunctionFilterEntryCurrent - 1) / (float)numFunctionFilterEntries) * amountOfProgressBarGiven)); var userState = new ProgressDialogUserState(); userState.NumberIterations = numFunctionFilterEntries; userState.CurrentIteration = numFunctionFilterEntryCurrent; userState.CurrentStatusMessage = string.Format( CultureInfo.CurrentCulture, Design.Resources.RetrievingSprocReturnTypeInfoMessage, numFunctionFilterEntryCurrent, numFunctionFilterEntries, entry.Schema, entry.Name); worker.ReportProgress(percentCompleted, userState); } // now retrieve and store the return type information var schemaProcedure = dataSchemaServer.GetProcedureOrFunction(entry.Schema, entry.Name); Debug.Assert( null == newFunctionSchemaProcedureMap[entry], "This entry has already been processed, Schema = " + entry.Schema + ", Name = " + entry.Name); newFunctionSchemaProcedureMap[entry] = schemaProcedure; } } } finally { if (null != dataConnection) { dataConnection.Close(); } } }
internal static string GetInitialCatalog(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { string initialCatalog = null; var invariantName = GetProviderInvariantName(dataProviderManager, dataConnection.Provider); var props = GetConnectionProperties(dataProviderManager, dataConnection); if (props != null) { if (props.ContainsKey(LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME) && !string.IsNullOrEmpty(props[LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME] as string)) { //sql client with "AttachDbFileName" parameter in the connection string. object o = null; props.TryGetValue(LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME, out o); initialCatalog = o as String; if (initialCatalog != null) { initialCatalog = Path.GetFileNameWithoutExtension(initialCatalog); } } else if (LocalDataUtil.IsSqlMobileConnectionString(invariantName)) { // sql CE object o = null; props.TryGetValue(LocalDataUtil.CONNECTION_PROPERTY_DATA_SOURCE, out o); initialCatalog = o as String; if (initialCatalog != null) { initialCatalog = Path.GetFileNameWithoutExtension(initialCatalog); } } else { object o = null; props.TryGetValue("Database", out o); initialCatalog = o as String; } } // save the default catalog if (string.IsNullOrEmpty(initialCatalog)) { var sourceInformation = dataConnection.GetService(typeof(IVsDataSourceInformation)) as IVsDataSourceInformation; Debug.Assert( sourceInformation != null, "Could not find the IVsDataSourceInformation for this IVsDataConnection to determine the default catalog"); if (sourceInformation != null) { initialCatalog = sourceInformation["DefaultCatalog"] as string; // Note: it is valid for initialCatalog to be null for certain providers which do not support that concept } } return(initialCatalog); }
private string GetDefaultAppConfigEntryName(IVsDataConnection dataConnection) { // get the initial catalog string from the connection var initialCatalog = DataConnectionUtils.GetInitialCatalog(_dataProviderManager, dataConnection); Wizard.ModelBuilderSettings.InitialCatalog = initialCatalog; // compute the connection string name return ConnectionManager.GetUniqueConnectionStringName( _configFileUtils, Wizard.ModelBuilderSettings.GenerationOption == ModelGenerationOption.CodeFirstFromDatabase ? Wizard.ModelBuilderSettings.ModelName : GetBaseEdmxConnectionStringName(initialCatalog)); }
internal static IVsDataConnectionProperties GetConnectionProperties( IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } IVsDataConnectionProperties properties = null; var provider = GetVsProvider(dataProviderManager, dataConnection); Debug.Assert(provider != null, "null provider value for dataConnection"); if (provider != null) { var dataSource = GetVsDataSource(dataProviderManager, dataConnection); properties = provider.TryCreateObject<IVsDataConnectionProperties>(dataSource); Debug.Assert(properties != null, "Could not get connection properties service"); if (properties != null) { var connectionString = DecryptConnectionString(dataConnection) ?? string.Empty; properties.Parse(connectionString); } } return properties; }
public DataSourceComboBoxItem(string displayName, IVsDataConnection connection) { Debug.Assert(null != connection, "connection should not be null"); _displayName = displayName; _dataConnection = connection; }
private void OnDoWork(object sender, DoWorkEventArgs e) { IDataSchemaProcedure storedProc = null; _openedDbConnection = Connection; if (_openedDbConnection != null) { var server = new DataSchemaServer(_openedDbConnection); var function = (Function)e.Argument; storedProc = server.GetProcedureOrFunction(function.DatabaseSchemaName, function.DatabaseFunctionName); } e.Result = storedProc; }
public void ResetDataConnection(IVsDataConnection dataConnection) { // do not need to reset _provider or _isConnectionStringEncrypted since these are the same // as original connection Debug.Assert(null != dataConnection, "dataConnection should not be null"); _dataConnection = dataConnection; }
private static Guid GetVsDataSource(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } var guid = Guid.Empty; var provider = GetVsProvider(dataProviderManager, dataConnection); guid = provider.DeriveSource(DataProtection.DecryptString(dataConnection.EncryptedConnectionString)); return(guid); }
internal static IVsDataProvider GetVsProvider(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } IVsDataProvider vsDataProvider = null; dataProviderManager.Providers.TryGetValue(dataConnection.Provider, out vsDataProvider); Debug.Assert( vsDataProvider != null, "Data provider identified by guid '{0}' could not be loaded" + dataConnection.Provider.ToString()); return(vsDataProvider); }
internal static string DecryptConnectionString(IVsDataConnection dataConnection) { return(dataConnection == null ? string.Empty : DataProtection.DecryptString(dataConnection.EncryptedConnectionString)); }
public SubSonicDataConnection(IVsDataConnection connection) { EncryptedConnectionString = connection.EncryptedConnectionString; SafeConnectionString = connection.SafeConnectionString; DisplayConnectionString = connection.DisplayConnectionString; }
public SqliteObjectIdentifierConverter(IVsDataConnection connection) : base(connection) { }
internal static IVsDataProvider GetVsProvider(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } IVsDataProvider vsDataProvider = null; dataProviderManager.Providers.TryGetValue(dataConnection.Provider, out vsDataProvider); Debug.Assert( vsDataProvider != null, "Data provider identified by guid '{0}' could not be loaded" + dataConnection.Provider.ToString()); return vsDataProvider; }
internal static void SetupSettingsAndModeForDbPages( IServiceProvider sp, Project project, EFArtifact artifact, bool checkDatabaseConnection, ModelBuilderWizardForm.WizardMode noConnectionMode, ModelBuilderWizardForm.WizardMode existingConnectionMode, out ModelBuilderWizardForm.WizardMode startMode, out ModelBuilderSettings settings) { var conceptualEntityModel = artifact.ConceptualModel(); Debug.Assert(conceptualEntityModel != null, "Null Conceptual Entity Model"); var entityContainer = conceptualEntityModel.FirstEntityContainer as ConceptualEntityContainer; Debug.Assert(entityContainer != null, "Null Conceptual Entity Container"); var entityContainerName = entityContainer.LocalName.Value; // set up ModelBuilderSettings for startMode=noConnectionMode startMode = noConnectionMode; settings = new ModelBuilderSettings(); var appType = VsUtils.GetApplicationType(sp, project); settings.VSApplicationType = appType; settings.AppConfigConnectionPropertyName = entityContainerName; settings.Artifact = artifact; settings.UseLegacyProvider = ModelHelper.GetDesignerPropertyValueFromArtifactAsBool( OptionsDesignerInfo.ElementName, OptionsDesignerInfo.AttributeUseLegacyProvider, OptionsDesignerInfo.UseLegacyProviderDefault, artifact); settings.TargetSchemaVersion = artifact.SchemaVersion; settings.Project = project; settings.ModelPath = artifact.Uri.LocalPath; // Get the provider manifest token from the existing SSDL. // We don't want to attempt to get it from provider services since this requires a connection // which will severely impact the performance of Model First in disconnected scenarios. settings.ProviderManifestToken = DatabaseGenerationEngine.GetProviderManifestTokenDisconnected(artifact); // Change startMode and settings appropriately depending on whether there is an existing connection string and whether we can/should connect // to the database var connectionString = ConnectionManager.GetConnectionStringObject(project, entityContainerName); if (connectionString != null) { var ecsb = connectionString.Builder; var runtimeProviderName = ecsb.Provider; var runtimeProviderConnectionString = ecsb.ProviderConnectionString; var designTimeProviderConnectionString = connectionString.GetDesignTimeProviderConnectionString(project); var initialCatalog = String.Empty; if (checkDatabaseConnection) { // This path will check to make sure that we can connect to an existing database before changing the start mode to 'existingConnection' IVsDataConnection dataConnection = null; try { var dataConnectionManager = sp.GetService(typeof(IVsDataConnectionManager)) as IVsDataConnectionManager; Debug.Assert(dataConnectionManager != null, "Could not find IVsDataConnectionManager"); var dataProviderManager = sp.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; Debug.Assert(dataProviderManager != null, "Could not find IVsDataProviderManager"); if (dataConnectionManager != null && dataProviderManager != null) { // this will either get an existing connection or attempt to create a new one dataConnection = DataConnectionUtils.GetDataConnection( dataConnectionManager, dataProviderManager, connectionString.DesignTimeProviderInvariantName, designTimeProviderConnectionString); Debug.Assert( dataConnection != null, "Could not find the IVsDataConnection; an exception should have been thrown if this was the case"); if (dataConnection != null) { VsUtils.EnsureProvider(runtimeProviderName, settings.UseLegacyProvider, project, sp); if (CanCreateAndOpenConnection( new StoreSchemaConnectionFactory(), runtimeProviderName, connectionString.DesignTimeProviderInvariantName, designTimeProviderConnectionString)) { startMode = existingConnectionMode; initialCatalog = DataConnectionUtils.GetInitialCatalog(dataProviderManager, dataConnection); } } } } catch { // do nothing - we will go to WizardPageDbConfig which is // what we want if the DB connection fails } finally { // Close the IVsDataConnection if (dataConnection != null) { try { dataConnection.Close(); } catch { } } } } else { // This path will just parse the existing connection string in order to change the start mode. This is ideal for features // that do not need a database connection -- the information in the connection string is enough. startMode = existingConnectionMode; initialCatalog = DataConnectionUtils.GetInitialCatalog( connectionString.DesignTimeProviderInvariantName, designTimeProviderConnectionString); } if (startMode == existingConnectionMode) { // the invariant name and connection string came from app.config, so they are "runtime" invariant names and not "design-time" // (Note: it is OK for InitialCatalog to be null at this stage e.g. from a provider who do not support the concept of Initial Catalog) settings.SetInvariantNamesAndConnectionStrings( project, runtimeProviderName, runtimeProviderConnectionString, runtimeProviderConnectionString, false); settings.InitialCatalog = initialCatalog; settings.AppConfigConnectionPropertyName = entityContainerName; settings.SaveConnectionStringInAppConfig = false; VsUtils.EnsureProvider(runtimeProviderName, settings.UseLegacyProvider, project, sp); } } }
internal static string GetInitialCatalog(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { string initialCatalog = null; var invariantName = GetProviderInvariantName(dataProviderManager, dataConnection.Provider); var props = GetConnectionProperties(dataProviderManager, dataConnection); if (props != null) { if (props.ContainsKey(LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME) && !string.IsNullOrEmpty(props[LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME] as string)) { //sql client with "AttachDbFileName" parameter in the connection string. object o = null; props.TryGetValue(LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME, out o); initialCatalog = o as String; if (initialCatalog != null) { initialCatalog = Path.GetFileNameWithoutExtension(initialCatalog); } } else if (LocalDataUtil.IsSqlMobileConnectionString(invariantName)) { // sql CE object o = null; props.TryGetValue(LocalDataUtil.CONNECTION_PROPERTY_DATA_SOURCE, out o); initialCatalog = o as String; if (initialCatalog != null) { initialCatalog = Path.GetFileNameWithoutExtension(initialCatalog); } } else { object o = null; props.TryGetValue("Database", out o); initialCatalog = o as String; } } // save the default catalog if (string.IsNullOrEmpty(initialCatalog)) { var sourceInformation = dataConnection.GetService(typeof(IVsDataSourceInformation)) as IVsDataSourceInformation; Debug.Assert( sourceInformation != null, "Could not find the IVsDataSourceInformation for this IVsDataConnection to determine the default catalog"); if (sourceInformation != null) { initialCatalog = sourceInformation["DefaultCatalog"] as string; // Note: it is valid for initialCatalog to be null for certain providers which do not support that concept } } return initialCatalog; }
public SqliteObjectSelector(IVsDataConnection connection) : base(connection) { }