Solved

IIS not allowing SQL connection

Posted on 2010-09-01
17
709 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:richard_hughes
  • 7
  • 4
  • 2
  • +4
17 Comments
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33576611
In Web.Config

your connection string is not correct

Please check SErver/DataSource
0
 

Expert Comment

by:asutorius
ID: 33576612
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
 
LVL 9

Author Comment

by:richard_hughes
ID: 33576622
Hello both

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

Thanks
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 42

Expert Comment

by:sedgwick
ID: 33576623
can u post the connection string?
0
 
LVL 9

Author Comment

by:richard_hughes
ID: 33576670
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
 
LVL 4

Expert Comment

by:gilberthye
ID: 33576678
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
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33576688
server=MyServer;database=CCDataBase;Integrated Security=false;User ID=Admin;Password=Vjsoft;Trusted_Connection=No;
0
 
LVL 9

Author Comment

by:richard_hughes
ID: 33576728
The connection string is using sa to login.

Thanks for your help so far!
0
 

Expert Comment

by:asutorius
ID: 33576775
Richard, using SSMS are you able to connect to the remote server using the credentials? (sa username as you mentioned above)
0
 
LVL 9

Author Comment

by:richard_hughes
ID: 33576788
Yes.
0
 

Expert Comment

by:asutorius
ID: 33576831
...and your conn string looks like what vjsoft recommended?
0
 
LVL 9

Author Comment

by:richard_hughes
ID: 33576920
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
 
LVL 6

Accepted Solution

by:
Jerryuk007 earned 500 total points
ID: 33577170
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33577259
Are you running Cassini and IIS on the same box, or is this two seperate machines?
0
 
LVL 9

Author Comment

by:richard_hughes
ID: 33577284
carl_tawn: What is Cassini?
0
 

Expert Comment

by:asutorius
ID: 33577315
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
 
LVL 9

Author Closing Comment

by:richard_hughes
ID: 33577383
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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question