ASP.NET connection string problem

midrange

Senior Member
Joined
Apr 8, 2009
Messages
727
I am a pre-novice in .NET so am having issues. I need to make changes to a site but need a local copy running first. I have downloaded the sql .bak file, have restored it and can view it in the management studio. I have the solution set up in VS 2008 but can't connect to the database.

In web.config I have this

Code:
<add name="DB" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=databasename;Integrated Security=True" providerName="System.Data.SqlClient"  />

When I try to view default.aspx the login fails with

Code:
Exception Details: System.Data.SqlClient.SqlException: Cannot open database "database" requested by the login. The login failed.
Login failed for user 'SQLServername\Username'.

I have added the login 'SQLServername\Username' (with Windows authentication) with DB_Owner permissions to the database but still get that error.

So my question is... HELP!
 

Optimus01

Well-Known Member
Joined
Nov 16, 2009
Messages
127
Gulp!

I dont like .asp much

Sorry I cant help, but Im sure there are some peeps here that are ASP gurus.
 

crazy_cat

Well-Known Member
Joined
Aug 21, 2007
Messages
326
just to clarify... the actual error message contains 'SQLServername\Username' ..:D or has this been sanitized

Also , when adding users to the DB, you need to do in two places under security settings.
1) The Database Server (i think its called logins); and
2) The actual database

Also, you may want to check that the your DB instance is configured to allow dual authentication i.e both sql server and windows although i doubt that this is the issue.

You may want to try and browse the db from VS using the Server explorer..

baby steps.....
 

midrange

Senior Member
Joined
Apr 8, 2009
Messages
727
baby steps...

:(

Got the client on my case and the only .net developer is away.

I've created a new user and in user mapping made it DB_OWNER on the table.

Now getting a "The user is not associated with a trusted SQL Server connection." error
 

midrange

Senior Member
Joined
Apr 8, 2009
Messages
727
Also, you may want to check that the your DB instance is configured to allow dual authentication i.e both sql server and windows although i doubt that this is the issue.

This was the issue with my last problem. Thanks Crazy Cat.
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Gulp!

I dont like .asp much

Sorry I cant help, but Im sure there are some peeps here that are ASP gurus.

Please refrain from "adding" anything to a thread you can't help with at all. I know back links are important but there's many other ways in doing so.
 

rabbiddog

Expert Member
Joined
Dec 29, 2004
Messages
1,219
Look in "My Project" under "Settings" to check the connection string.

Integrated security would look like this:
Data Source=LAPTOP;Initial Catalog=DBNAME;Integrated Security=True

or else it would have user name in it something like this:
Provider=SQLOLEDB.1;Password=Passwd;Persist Security Info=True;User ID=me;Initial Catalog=DBNAME;Data Source=LAPTOP
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Will do when I have time to properly learn this stuff. For now I have it working, largely through sheer luck.

Funny, one look at that website should have saved you the time you spent in making it work... but anyway... what do WE know. WE just do this for a living :rolleyes:
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
did you come right with the problems you are having?

Yes he did according to his post above dequadin's. Reading isn't just for n00bs ;)

Copy paste that into Google, the first link is the Microsoft KB article on that problem.

It seems to me like your problem is on the SQL side and not the ASP side...

There's a multitude of issues he could have been facing there, but without a proper connection string we can't really determine the exact cause. My first thought was "Oh, he probably didn't turn on Mixed-Mode to be able to login with a user..." but he didn't confirm the connection strings he tried nor did he give any feedback on if he even bothered with our suggestions or not.

All in all. It appears that our experience in this field has apparently just wasted his time...
 
Last edited:

rurapente

Expert Member
Joined
Jan 4, 2009
Messages
2,521
if you're not specifying a username, i;e using persistent security it will use the context user that the ASP.NET script is running in. so either you run the entire thing as the user who has access to the SQL DB (which, although used by many developers, will get you shot, and hanged on a flagpole) or set impersonation for the user authenticated to the script.
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
if you're not specifying a username, i;e using persistent security it will use the context user that the ASP.NET script is running in. so either you run the entire thing as the user who has access to the SQL DB (which, although used by many developers, will get you shot, and hanged on a flagpole) or set impersonation for the user authenticated to the script.

Thanks for the insight, however, I don't think the OP wanted to be helped...
 
Top