Can Someone Help Me With This SqlConnectionString?
Nov 17, 2007Hi.
I just uploaded our website on a free hosting service, called aspspider.net. I am having problems with the database. I uploaded the .mdf file and attached it. I think the problem lies with the sqlConnectionString, and I was hoping someone could help me it.
First off, here is a tip from the hosting developers on how to set the connection string:
http://www.aspspider.net/tips/Tip18.aspx.
It says, "Data Source=.SQLExpress;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=YourUserId_DatabaseName"
My UserId (that I signed up with) is "RedTeamBattleship", and the database name that I uploaded is called "ASPNETDB.MDF".
Now here is what I had in TestDatabase.aspx.cs, running on the localhost. It used to work fine:String sqlConnectionString = @"Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Integrated Security=True;User Instance=True"; // connects to the localhost Following their pattern, I made the following connection string:String sqlConnectionString = @"Data Source=.SQLExpress;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=RedTeamBattleship_ASPNETDB.MDF"; // connects to the DB hosted on ASPSpider
Unfortunately, it did not work. I tried to Google for a solution, and someone had mentioned their problem was solved when they added "user instance=false;" so I added it. However, I didn't notice any difference.String sqlConnectionString = @"Data Source=.SQLExpress;Persist Security Info=True;Integrated Security=SSPI;user instance=false;Initial Catalog=RedTeamBattleship_ASPNETDB.MDF"; // connects to the DB hosted on ASPSpider
Now every time I run the application, I get the following exception: Server Error in '/RedTeamBattleship' Application.
Cannot open database "RedTeamBattleship_ASPNETDB.MDF" requested by the login. The login failed.
Login failed for user 'DOTNETSPIDER3RedTeamBattleship'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot open database "RedTeamBattleship_ASPNETDB.MDF" requested by the login. The login failed.
Login failed for user 'DOTNETSPIDER3RedTeamBattleship'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Cannot open database "RedTeamBattleship_ASPNETDB.MDF" requested by the login. The login failed.
Login failed for user 'DOTNETSPIDER3RedTeamBattleship'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +739123
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1956
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +170
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +349
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +359
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360
In addition, I changed the one in the Web.Config file, though I'm not sure if I should have done so.
I changed it from:
<connectionStrings> <add name="MyDbConn1" connectionString="Server=MyServer;Database=MyDb;Trusted_Connection=Yes;"/> <add name="MyDbConn2" connectionString="Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;"/> <add name="ConnectionString" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/> </connectionStrings>
To:
<connectionStrings> <add name="MyDbConn1" connectionString="Server=MyServer;Database=MyDb;Trusted_Connection=Yes;"/> <add name="MyDbConn2" connectionString="Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;"/> <add name="ConnectionString" connectionString="Data Source=.SQLExpress;Persist Security Info=True;Integrated Security=SSPI;user instance=false;Initial Catalog=RedTeamBattleship_ASPNETDB.MDF" /> </connectionStrings>
And the application still crashes with the same way.
Can someone help me fix that problem? Thank you very much.