2

I'm developing a website using Visual Studio 2008 and Sql Server 2008 Express. I entered into developing, so code is right as there are some coleagues of mine running it correctly with the same tools. The problem is: once I run the website I cannot make it comunicate with the database. They both are in my local machine. The error thrown is:

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

The strange stuff is that I can navigate the db throught Visual Studio itself, via the Data Explorer panel. By doing that, I read the connection string from properties, and it looks like

Data Source=*MY_MACHINE*\SQLEXPRESS;Initial Catalog=*MY_DB*;Integrated Security=True

I also tried some change like

Data Source=.\SQLEXPRESS;Initial Catalog=*MY_DB*;Integrated Security=True

Data Source=localhost\SQLEXPRESS;Initial Catalog=*MY_DB*;Integrated Security=True

both with no results.

Thanks

2
  • is the SQL Browser service turned on on your local machine? Commented Jan 9, 2013 at 18:06
  • yes, both SQL Server and SQL Server Browser services are running on my machine. Commented Jan 9, 2013 at 18:07

1 Answer 1

1

The problem is the ASP.NET worker process does not have rights to access the database.

There are a number of ways to fix this, but the simplest is to give local group everyone rights to the database. Then you should be able to connect.

or

You could change the connection string to not use Integrated Security but give it a username and password

You should also see an appropriate error message in your event log (saying USER such and such was not allowed to access the database) then you can give rights to just that user.

When you are running as yourself you are connecting as yourself and you have rights. When IIs is running then it is running as the worker process and that user can't connect.

Sign up to request clarification or add additional context in comments.

7 Comments

I tried both ways. For the first one, in the processes list I see the web server process to be assigned to my user, so it seems not to happen te issue you told (which, anyway, sounds reasonable: any chance I'm wrong in detecting the right user?). For the second way, I created a new user, grant every permission and all, but still the same error. So I ask: is there a way to check the database is correctly online and is reachable?
It could be that it (or a thread) is running as a different identity. Did you check the event logs on the machine? Creating a new user is not the solution -- you have to add the worker process user to the SQL Server security setup. (Maybe that is what you meant?)
Yep, let focus on this: how I recognize the proper worker process user?
I think the first step should be to use a connection string that has your username and see if that fixes the problem -- if it does then you can look into giving the worker process rights or running the worker process as a specified user. (How to do this is detailed in IIs documentation).
I've just did it, and it didn't work. You mentioned IIS: I don't have a proper IIS installation, I'm using the one shipped with Visual Studio (wich actually is named Visual Web Developer 2008 Express Edition)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.