Solved

IIS not allowing SQL connection

Posted on 2010-09-01
17
706 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
Comment Utility
In Web.Config

your connection string is not correct

Please check SErver/DataSource
0
 

Expert Comment

by:asutorius
Comment Utility
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
Comment Utility
Hello both

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

Thanks
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
can u post the connection string?
0
 
LVL 9

Author Comment

by:richard_hughes
Comment Utility
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
Comment Utility
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
Comment Utility
server=MyServer;database=CCDataBase;Integrated Security=false;User ID=Admin;Password=Vjsoft;Trusted_Connection=No;
0
 
LVL 9

Author Comment

by:richard_hughes
Comment Utility
The connection string is using sa to login.

Thanks for your help so far!
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Expert Comment

by:asutorius
Comment Utility
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
Comment Utility
Yes.
0
 

Expert Comment

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

Author Comment

by:richard_hughes
Comment Utility
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
Comment Utility
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
Comment Utility
Are you running Cassini and IIS on the same box, or is this two seperate machines?
0
 
LVL 9

Author Comment

by:richard_hughes
Comment Utility
carl_tawn: What is Cassini?
0
 

Expert Comment

by:asutorius
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now