IIS not allowing SQL connection

Hello All

My system setup is this:

Windows 7 x86
IIS 7.5
Visual Studio 2008 SP1

I have setup a website using ASP .NET 2.

My problem is this:

If I run this site using the standard Visual Studio Web Server, it works fine. If, though, I run the site using IIS, I get the following error:

System.Data.OleDb.OleDbException: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OleDb.OleDbConnection.Open() at .....

Thanks,

Richard Hughes
LVL 9
richard_hughesAsked:
Who is Participating?
 
Jerryuk007Connect With a Mentor Commented:
You're trying to use Named Pipes... Try to use TCPIP which can be specified in your SQL Connection String.
Also ensure that your SQL Instance is configured to accept TCP IP connections.

Jerry
0
 
Mohit VijayCommented:
In Web.Config

your connection string is not correct

Please check SErver/DataSource
0
 
asutoriusCommented:
Two things...1) what does your web.config look like and 2) using SSMS (SQL Server Management Studio) can you actually connect to the sql server using the credentials you are trying to use in the website code?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
richard_hughesAuthor Commented:
Hello both

The connection string is fine, because the site works as expected when running under the Visual Studio Web Server.

Thanks
0
 
Meir RivkinFull stack Software EngineerCommented:
can u post the connection string?
0
 
richard_hughesAuthor Commented:
As an added note, the database is located on a remote server.

So when under Visual Studio, it works fine, when under IIS, it doesn't.
0
 
Gilberth YeIT Senior ExecutiveCommented:
This is definately a security issue. In your connection string, you are using Windows integrated authentication to connection to the server most likely.VS.NET is using your windows identity. However, the ASP.NET app is running under the ASPNET account, which doesn't have that previlege. To resolve this, you can either give the ASPNET account proper permission to access the database, or use other accounts for accessing the database.

if it is other issues, u can go http://support.microsoft.com/kb/888228 for support
0
 
Mohit VijayCommented:
server=MyServer;database=CCDataBase;Integrated Security=false;User ID=Admin;Password=Vjsoft;Trusted_Connection=No;
0
 
richard_hughesAuthor Commented:
The connection string is using sa to login.

Thanks for your help so far!
0
 
asutoriusCommented:
Richard, using SSMS are you able to connect to the remote server using the credentials? (sa username as you mentioned above)
0
 
richard_hughesAuthor Commented:
Yes.
0
 
asutoriusCommented:
...and your conn string looks like what vjsoft recommended?
0
 
richard_hughesAuthor Commented:
I had to change to a SqlConnection rather than an OleDbConnection, so yes.

I get this error with the SqlConnection:

System.Data.SqlClient.SqlException: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) at ...

Thanks
0
 
Carl TawnSystems and Integration DeveloperCommented:
Are you running Cassini and IIS on the same box, or is this two seperate machines?
0
 
richard_hughesAuthor Commented:
carl_tawn: What is Cassini?
0
 
asutoriusCommented:
Does the server name in your connection string reflect a fully qualified domain name for the server and the instance?

You mentioned that you were able to connect via SSMS without issue so I'm wondering what server name/instance name it's using to connect.

Can you post any of that information so we can do some comparisons?
0
 
richard_hughesAuthor Commented:
Thanks for all of your help guys!

It turns out that the server I was connecting to was using a non-standard TCP port. I am unsure how SSMS and VS was able to connect, but I can now connect via IIS too.

Thanks again,

Richard Hughes
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.