views:

2618

answers:

4

SQL Express 2005 is running locally. I have a project written by another person running on the same machine. All I want to do is connect to it, can't be that hard right?

This is the one I use in my old classic ASP code to hit another database running on the same instance:

Provider=SQLOLEDB;Data Source=MYLAPTOP\MSSMLBIZ;Persist Security Info=True;User ID=TestUser;Password=letmein;Initial Catalog=TestDB

But trying a version of that makes the .net code throw a wobbler as he's written it using SQLServer drivers so its not liking the Provider stuff.

Here is the orginal connection string from his code:

Server=(local);Initial Catalog=TheDatabase;User Id=TheUser;Password=ThePassword;

I've been to http://www.connectionstrings.com/sql-server-2005 and tried several of the options from there, these all get "SQL Server does not exist or access denied" (what a lovely mixed error message that is!):

  • Data Source=localhost;Integrated Security=True;Initial Catalog=TheDatabase
  • Data Source=localhost\SQLEXPRESS;Integrated Security=True;Initial Catalog=TheDatabase
  • Data Source=MyLaptop\SQLEXPRESS;Integrated Security=True;Initial Catalog=TheDatabase
  • Server=MyLaptop\SQLEXPRESS;Initial Catalog=TheDatabase;User Id=TheUser;Password=ThePassword;

I've created logins for MyLaptop/IUSR_MyLaptop, MyLaptop/ASPNET, MyLaptop/IWAM_MyLaptop in SQL Express and given them all read/write permissions to my DB and set their default DB to be TheDatabase.

What the heck am I doing wrong and how can I debug the problem some more?

UPDATE: Special Thanks to Chris for all his pointers, got there in the end, if you are having similar problem please read all the comments there are lots of links and tips on how to track them down.

A: 

Shouldn't your datasource read: Data Source=localhost\sqlexpress too?

Tanner
Tried that one, added it in above.
Pete Duncanson
A: 

You don't mention granting rights for 'TheUser' to access the database on the server - if you're restored from another server you may had a sid mismatch.

Try running

sp_update_users_login 'report'

against the db in question.

If it returns the user account in the report try:

sp_update_users_login 'update_one', 'theuser', 'theuser'

to remap things.

Chris W
I don't appear to have that stored procedure available? Msg 2812, Level 16, State 62, Line 1Could not find stored procedure 'sp_update_users_login'.
Pete Duncanson
sorry - it should have been sp_change_users_login ... but it's probably not relevant if you can't even get a basic connection to the server.
Chris W
Ok got that to run, there only one entry, one from when the developer ran the DB I guess. Not one of mine. I did restore the DB but added my users back in afterwards. Whats this report telling me Chris?
Pete Duncanson
That will tell you mismatched users - i.e. where the sid of the user on your server doesn't match the one in the database itself. A common issue when moving dbs between servers. If the content in the report is not the username you're trying to connect with then just ignore it.
Chris W
+1  A: 

With that error message in your comment you should run through the items in http://blogs.msdn.com/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx

I presume the instance is running and does allow connections over tcpip?

Chris W
Reading that article now, downloading the PortQry too. Yes instance is running and from what I've read and seen it "should" be allowing tcpip. Disabled dynamic ports and set it to always use 1434. Do I need that though if running local?
Pete Duncanson
No - it shouldn't matter if connecting locally but you've got something strange happening - how are you administering the server at the moment. SSMS? Are you connecting with a windows or sql login?
Chris W
In Configuration Manager - check the Client Config to see what protocols are enabled on for connecting and the order they're applied.
Chris W
Yes using Microsoft SQL Server Management Studio Express with a Windows login. Goes in just fine. Also I've switched on Dynamic ports again by setting it to 0 and changed the tcpip port to 1433 which I believe is the right one (1434 is for the SQL Browser from what I've read). More info in a minute...
Pete Duncanson
Shared Memory 1, TCPIP 2, Pipe 3...does that help? :|
Pete Duncanson
Right its now connecting via the command line! Dare I admit I had a typo in the server name. Sorry. Whats next though? I'm completely out of ideas. To be sure I've checked everything else too, no more typos anywhere.
Pete Duncanson
Was that with the -E switch (windows auth)? You can now try sqlcmd -S localhost\mssmlbiz -U username -P password to verify that you can log in using the credentials that you think should be able to use.
Chris W
Ok, reinstalled, setup my users again and tried the above and get: "Login failed for user '<MyUserName>'.The user is not associated with a trusted SQL Server connection."
Pete Duncanson
Chris that narrowed it down. Thanks. Googling the above I found this page which explains that I did not have SQL Server authentication switched on (the default is to only use Windows Auth). Switched than and used your cmd prompt above and all sorted.http://www.electrictoolbox.com/user-not-assocated-trusted-sql-server-connection/
Pete Duncanson
+1  A: 

Can you advise exactly what is in the config?

Are you using the block - in which case a valid connection string would be:

<add name="connection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost\MSSMLBIZ;Initial Catalog=TheDatabase;Integrated Security=True" />

or

<add name="connection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost\MSSMLBIZ;Initial Catalog=TheDatabase;Integrated Security=False;User Id=TheUser;Password=ThePassword;Application Name=AppName;" />

Or are you getting the connection string from app settings - in which case I guess your provider is set in code inside the app itself?

Chris W
app settings, its .Net Version 1 (due to a limitation of where it will be hosted). Reinstall is not going well either...one of those days...
Pete Duncanson
And thanks for your help too Chris, much appreciated, DB setup is not really my bag...
Pete Duncanson