works on SQL Management Studio machine, fails on SQL Express machine

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello all,
Sorry in advance for the length of this, but Im trying to make sure all the relevant info is out there at the start.
development machine:
XP Pro, SP3
VS 2008 Pro, SP1
SQL Server 2005 Management Studio
testing machine:
<running in VM>
XP Pro, SP3
.NET 3.5, SP1 (not the version from VS installer)
SQL Server Express, SP 4 (also not the version from VS installer)
I have two SQL 2005 databases, call them S and O. I have created a SQL file using the Database Publishing Wizard containing schema and data for the databases (with an edit to point to the MSSQL.1 data directory used by SqlExpress for the testing machine). The program in question is a C# console app that runs fine on my development machine.
The problems arise when I switch to the test machine. All actions are performed by an administrator account. SqlExpress was installed using all defaults. I then verified that SQL Server Surface Area Configuration only allows local connections. I then ran SQL Server Network Configuration and verified that the Protocols only allow Shared Memory and changed the Network Client Protocols to only allow Shared Memory. This matches the SQL Server setup on the development machine. Reboot the test machine.
I then copy my console program EXE, required DLLs, and an EXE.CONFIG and DLL.CONFIG that have the connection strings modified (using Enterprise Library Configuration Tool) so that DataSource now reads "NameVMsqlexpress" -- all other values are unchanged from that created by VS (Data Source=NameVMsqlexpress;Initial Catalog=S;Integrated Security=True).
I populate my DBs by opening a command prompt and running
sqlcmd -S NameVMsqlexpress -i <script.sql>
This commands runs like a champ.
In the exact same command window, I then attempt to run my console program - it fails.
And now for the gory details on the console program ...
It is a program wrapping the logic that will eventually move into a service, so the console part of it basically sits waiting for the user to enter commands like "start" "stop" "suspend and "resume" to simulate SCM commands.
All DB table manipulation is done using the Data Sets created by VS -- I "new" a dataTable and tableAdapter then use the GetData functions in the tableAdapter.
During "start" processing, it accesses both databases S and O. It then launches a thread usingThreadPool.QueueUserWorkItem and then waits for the thread to finish its startup logic. It then blindly launches a second thread and exits "start" processing. The first thread is failing on the test machine.
The first threads startup uses Assembly.LoadFile / Type.GetInterface/ Activator.CreateInstance to fire up an instance of a class / interface from a DLL. The thread next accesses database S (successfully!!) then makes a couple of calls into that interface. The first 2 calls, which do NOT need the DB, succeed. The third function call into the interface launches another thread (via new Thread (new ThreadStart (thrdFunc)).Start) which in turn calls a static class in another DLL to access database S. This call fails with the following error and stack trace:
System.Data.SqlClient.SqlException: 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)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at CommonRoutines.DatabaseS_DataSetTableAdapters.TableSC_TableAdapter.GetDataByGuid(Guid Param1)
at CommonRoutines.ProtectClass.Unprotect(Byte[] data)
at ConnectionLibrary.CommClass.commandThreadFunc()
at ConnectionLibrary.CommClass.Connect()
at ConnectionLibrary.BaseConnection.Connect()
at Server.ConnectionManager.Connect()
at Server.AsyncStatusThread.MainLoop()
The last 2 lines in the call stack (Server) are the first thread started by the "start" logic. The next 3 lines up (ConnectionLibrary) are in the accessed-by-interface class in the first DLL. The next 2 lines up (CommonRoutines) are the static class in the other DLL.
Noting the call to CreatePooledConnection in the stack, I tried settingPooling=false in all the connection strings and the error is exactly the same.
I tried making the static class NOT static and the error is the same.
Im stumped. If its really a "server not found or inaccessible" error, why does it a) work on the development machine, and b) not fail on the first accesses to database S? Theres got to be something different between SqlExpress and regular SqlServer ... Is there something in SqlExpress that controls the number / type / source of connections that is different than regular SqlServer that is making it fail after only a hundred or so Gets? Does SqlExpress really care how the thread that is making the access came into life - its all the same process? Whats the difference between the two!?!?
Any and all suggestions would be appreciated since Im about out of things to try.
Thanks,
Judy

View the full article
 
Back
Top