Friday, February 24, 2012

Can someone help me with this sqlConnectionString?

Hi.

I just uploaded our website on a free hosting service, calledaspspider.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 Errorin'/RedTeamBattleship' Application.
Cannot open database"RedTeamBattleship_ASPNETDB.MDF" requested by the login. The login failed.
Login failedfor user'DOTNETSPIDER3\RedTeamBattleship'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack tracefor more information about the error and where it originatedin the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot open database"RedTeamBattleship_ASPNETDB.MDF" requested by the login. The login failed.
Login failedfor user'DOTNETSPIDER3\RedTeamBattleship'.

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 identifiedusing the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): Cannot open database"RedTeamBattleship_ASPNETDB.MDF" requested by the login. The login failed.
Login failedfor user'DOTNETSPIDER3\RedTeamBattleship'.]
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.

PieCook:

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

I believe because you are using Integrated Security, what that means is you will be logging into the database under the context of the account the ASP.NET worker process is running under.

You will need to check the account that is used when a user connects to IIS, you can check this from going to IIS, select your virtual directory and right click properties and select the directory security tab. The account listed there must be added to your database logins.

|||

Thank you for replying. I did as you said I should, but I'm not sure how to proceed from there:

I opened the "Default SMTP Virtual Server Properties" window, and here is what I see under the Security tab:


Grant operator permissions to these Windows user accounts.

Operators:

And inside the listbox, I see the following items:

Administrators

COMPUTER\ASP

COMPUTER\Guest

COMPUTER\HelpAssistant

COMPUTER\ISUR_COMPUTER

COMPUTER\IWAM_COMPUTER

COMPUTER\Jim

COMPUTER\SUPPORT_388945a0

jimmy q:

PieCook:

String sqlConnectionString = @."Data Source=.\SQLExpress;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=RedTeamBattleship_ASPNETDB.MDF";// connects to the DB hosted on ASPSpider

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

I believe because you are using Integrated Security, what that means is you will be logging into the database under the context of the account the ASP.NET worker process is running under.

You will need to check the account that is used when a user connects to IIS, you can check this fromgoing to IIS, select yourvirtual directory and right clickproperties and select the directorysecurity tab. Theaccount listed there must be added to your database logins.

So it seems I had the ASP.NET worker process (COMPUTER\ASPNET), and it was already added. Or am I looking at the wrong place?

Thank you very much for your time.

|||

You are a looking at the wrong place.

Under IIS, there are web sites, and in web sites there are virtual directories, and one of these are your web site application. What you are looking at is the SMTP server and not the web site.

Do you have access to this hosting service?

|||

Try it without the .MDF extension (in the connect string).

|||

Thank you all for replying.

jimmy q:

You are a looking at the wrong place.

Under IIS, there are web sites, and in web sites there are virtual directories, and one of these are your web site application. What you are looking at is the SMTP server and not the web site.

Do you have access to this hosting service?

OK, I got it this time, so it seems I have access to this hosting service... I think. Here is a screenshot of what I got:

http://i206.photobucket.com/albums/bb211/piecook/IIS%20Web%20Site/IISWebSiteVirtualDirectory.jpg

I went to the Directory Security tab and then clicked Edit, and the account I found was IUSR_COMPUTER.


Now you said earlier that "the account listed there must be added to your database logins." Can you please tell me how to do that?

david wendelken:

Try it without the .MDF extension (in the connect string).

I tried that, but it gave me the exact same error.

Thanks again.

|||

PieCook:

david wendelken:

Try it without the .MDF extension (in the connect string).

I tried that, but it gave me the exact same error.

No problem, but you may have two errors - a security error you are trying to work past and the one I mentioned. Keep it in mind as you work thru the other problem. :)

|||

PieCook:

OK, I got it this time, so it seems I have access to this hosting service... I think. Here is a screenshot of what I got:

http://i206.photobucket.com/albums/bb211/piecook/IIS%20Web%20Site/IISWebSiteVirtualDirectory.jpg

I went to the Directory Security tab and then clicked Edit, and the account I found was IUSR_COMPUTER.


Now you said earlier that "the account listed there must be added to your database logins." Can you please tell me how to do that?

What database are you using? If you using SQL Server you can use Enterprise Manager/Management Studio to login. There is a node called Security and under that Logins. You need to create a login for that IUSR account and map it to the database.

|||

Thanks everyone for the replies.

david wendelken:

No problem, but you may have two errors - a security error you are trying to work past and the one I mentioned. Keep it in mind as you work thru the other problem. :)

I read elsewhere that we shouldn't have the .MDF extension, just like you said. Thanks. Now one more problem remains, and I'll be back in business ^^

jimmy g:

What database are you using? If you using SQL Server you can useEnterprise Manager/Management Studio to login. There is a node calledSecurity and under that Logins. You need to create a login for thatIUSR account and map it to the database.

Yes, I am using SQL Server. I'll try to download SQL Server Management Studio from the link below, and I'll let you know what I did.

http://www.microsoft.com/downloads/details.aspx?FamilyID=c243a5ae-4bd1-4e3d-94b8-5a0f62bf7796&DisplayLang=en

Thank you very much.

|||

PieCook:

Yes, I am using SQL Server. I'll try to download SQL Server Management Studio from the link below, and I'll let you know what I did.

If you are using SQL Server 2000 it should come with Enterprise Manager unless you are using MSDE.

SQL Server 2005 also comes with Management Studio unless you are using Express.

|||

I'm using Microsoft Visual Web Developer 2005 Express Edition, and I manage the SQL Server database from the database explorer. I did download the SQL Server Management Studio Express to do what you suggested.

jimmy q:

If you using SQL Server you can useEnterprise Manager/Management Studio to login. There is a node calledSecurity and under thatLogins. You need tocreate a login for thatIUSR account andmap it to the database.

Here are the steps I took:

* I downloaded the program, and in the Object Explorer, I went to Security -> Logins.

* I right-clicked Logins and selected New Login.

* In the General tab/page, I clicked Search -> Advanced -> Find Now.

* I clicked "IUSR_COMPUTER" followed by OK -> OK. This typed "COMPUTER\IUSR_COMPUTER" in the textbox next to Login name. I then clicked OK.

Now I wasn't sure whether this is right, but I right-clicked "COMPUTER\IUSR_COMPUTER" and selected Properties, then selected the User Mappings page/tab. There are four databases available:

- master

- model

- msdb

- tempdb

So I checked the Map checkbox next to "master." Below that, there were many checkboxes concerning the "Database role membership for: master." By default, public was the only one checked, but I checked them all, as shown in this screenshot:

http://i206.photobucket.com/albums/bb211/piecook/IIS%20Web%20Site/SQLServerLoginProperties.jpg


Can you tell me the next step?

Again, your help and patience is greatly appreciated. Thank you.

|||

Is your database not listed there? the 4 databases you mentioned are all system databases.

You are meant to be doing this for your database, so you need to be connecting to the database server. Is the database server on the hosted web server as well?

Once you have added the appropriate account to the login list, you should be able to connect to the database.

This use may be'DOTNETSPIDER3\RedTeamBattleship'or the IUSRaccount depending on how your IIS is configured, so try add both to the logins and do a process of elimination.

|||

jimmy q:

You are meant to be doing this for your database, so you need to be connecting to the database server. Is the database server on the hosted web server as well?

Sorry, I'm not quite sure what you mean. I followed the instructions in [ http://www.aspspider.com/tips/Tip16.aspx ] on how to attach the database file. I hope this means my database server is on the hosted web server as well.

jimmy q:

Once you have added the appropriate account to the login list, you should be able to connect to the database.

I think I already added the IUSR_COMPUTER account (by clicking search and letting it find the file). But how can I findDOTNETSPIDER3\RedTeamBattleship? It's not on the local system. Sorry if this is a beginner question.

|||

PieCook:

Sorry, I'm not quite sure what you mean. I followed the instructions in [ http://www.aspspider.com/tips/Tip16.aspx ] on how to attach the database file. I hope this means my database server is on the hosted web server as well.

What I am trying to say is you have to be doing all this on your database server. when you open Managemet Studio you should be connecting to your SQL Server Instance. This is where your database lives, and it is on this instance where you have to add the appropriate user logins.

You mention that you only see the 4 databases you mentioned before, that indicates that you are not logging onto the correct SQL instance as you should be able to see you database in that list.

|||

For some reason, I went to bed, and when I woke up I realized that the website was working... (?)

I also did not connect to the server database; I only followed your instructions until post #10, and then the database worked. I'm pretty sure I made no changes to the Web.Config file (although I was tempted to). But, it seems that your instructions did help somehow; I'm just not sure which specific post did it.

Thank you very much for spending the time and helping me out.Yes

Cheers.

No comments:

Post a Comment