Active Query Builder support area

Unhandled connection exception

Avatar
  • updated
  • Completed
Just press ctrl+space with invalid connection string in metadata provider.
Avatar
Andrey Zavyalov, PM
Hi.

Unfortunately we can not even start to investigate the described problem without having the necessary information.

1. What edition of Active Query Builder you use (Winforms, ASP.NET, VCL, ActiveX, Java)? What version?
2. In which demo project this problem can be reproduced, when you have pressed these keys? A screenshot might be helpful to understand the situation.

Avatar
inqb
I'm using Active Query Builder 2 .NET Professional Edition 2.7.2.627
I've noticed problem occurring in my solution, here's call stack of your library:

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at ActiveDatabaseSoftware.ActiveQueryBuilder.MSSQLMetadataProvider.DoConnect() in [...]\ActiveDatabaseSoftware\MsSqlMetadataProvider\MSSQLMetadataProvider.cs:line 72
at ActiveDatabaseSoftware.ActiveQueryBuilder.BaseMetadataProvider.Connect() in [...]\ActiveDatabaseSoftware\ActiveQueryBuilderNET\Metadata\BaseMetadataProvider.cs:line 356
at ActiveDatabaseSoftware.ActiveQueryBuilder.MSSQLMetadataProvider.LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions) in [...]\ActiveDatabaseSoftware\MsSqlMetadataProvider\MSSQLMetadataProvider.cs:line 147
at ActiveDatabaseSoftware.ActiveQueryBuilder.MetadataList.LoadPrivate(MetadataType loadTypes, Boolean allowDatabaseQueries, String mask) in [...]\ActiveDatabaseSoftware\ActiveQueryBuilderNET\Metadata\MetadataList.cs:line 484
at ActiveDatabaseSoftware.ActiveQueryBuilder.MetadataList.Load(MetadataType loadTypes, Boolean recursive) in [...]\ActiveDatabaseSoftware\ActiveQueryBuilderNET\Metadata\MetadataList.cs:line 724
at ActiveDatabaseSoftware.ActiveQueryBuilder.MetadataItem.LoadAll(Boolean withFields) in [...]\ActiveDatabaseSoftware\ActiveQueryBuilderNET\Metadata\MetadataItem.cs:line 873
at ActiveDatabaseSoftware.ExpressionEditor.SuggestionObjectList.ReloadMetadataPart(Boolean useAltNames, Boolean loadAllFromServer) in [...]\ActiveDatabaseSoftware\ExpressionEditor\SuggestionObjectList.cs:line 216
at ActiveDatabaseSoftware.ExpressionEditor.SuggestionObjectList.ReloadData(Boolean useAltNames) in [...]\ActiveDatabaseSoftware\ExpressionEditor\SuggestionObjectList.cs:line 97
at ActiveDatabaseSoftware.ExpressionEditor.SqlTextEditor.PopulateListBox(String filter, String[] nameParts, Boolean forceReload) in [...]\ActiveDatabaseSoftware\ExpressionEditor\SqlTextEditor.cs:line 753
at ActiveDatabaseSoftware.ExpressionEditor.SqlTextEditor.ShowSuggestions(Boolean force) in [...]\ActiveDatabaseSoftware\ExpressionEditor\SqlTextEditor.cs:line 639
at ActiveDatabaseSoftware.ExpressionEditor.SqlTextEditor.OnPreProcessKey(Keys keyData, Boolean& handled) in [...]\ActiveDatabaseSoftware\ExpressionEditor\SqlTextEditor.cs:line 487
at ActiveDatabaseSoftware.ExpressionEditor.TextEditorControl.TextView.ProcessDialogKey(Keys keyData) in [...]\ActiveDatabaseSoftware\ExpressionEditor\TextEditorControl\TextView.cs:line 778

Avatar
Andrey Zavyalov, PM
The database exception occurs on trying to get list of database objects for autocompletion, but connection string is incorrect, so the SqlException occurs notifying the user about this problem. You can check the database connection before allowing the end-user to work with Active Query Builder and notify user about this problem it in another way. You can set the QueryBuilder.OfflineMode to True to let the user work with Active Query Builder without live connection to the database.
Avatar
inqb
Connection string validation is not a solution, as it would only reduce the amount of exceptions, not get rid of them.
We'd like to handle the exceptions by logging them and continuing with no autocompletion, but neither System.Windows.Application.DispatcherUnhandledException nor System.Windows.Forms.Application.ThreadException are raised (we're using the query editor in a WPF application with WindowsFormsHost), so the app just crashes.
See attached example (you need to fill the lib dir with ActiveQueryBuilder2, ExpressionEditor2 and MSSQLMetadataProvider2 dlls)
http://s000.tinyupload.com/index.php?file_id=80540252589071688787
Avatar
Many thanks for the example.
We have fixed the unhandled exception, please download the update.
But we would like to recommend you to implement the connection string validation anyway:
	MSSQLMetadataProvider metadataProvider = new MSSQLMetadataProvider
	{
		Connection = new SqlConnection
		{
			ConnectionString = "Data Source=localhost;User ID=foo;Password=bar"
		}
	};
	try
	{
		metadataProvider.Connect();
	}
	catch (System.Data.Common.DbException dbException)
	{
		// dispatch DB error
	}
	var queryBuilder = new QueryBuilder
	{
		MetadataProvider = metadataProvider,
		...
	};