Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IIS not allowing SQL connection

Posted on 2010-09-01
17
Medium Priority
?
717 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 42

Expert Comment

by:Meir Rivkin
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:Gilberth Ye
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

916 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