Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
am developing an asp.net application with sqlserver using vs2008. When i run the application from vs2008, it works fine. But after publishing it to my local iis folder (i.e. C:\inetpub\wwwroot), it could not access the database.

What should i do? Do i have to change my connection string?? This is the one am using:

C#
SqlConnection conn = new SqlConnection("Data Source=salisu-pc\\sqlexpress;Initial Catalog=NNPC;Integrated Security=True;Pooling=True");


[OP's Answer moved to question]
thanks. The generating this exception:

System.Data.SqlClient.SqlException: Cannot open database "NNPC" requested by login. Then login failed.
Login failed for user "IIS APPPOOL\DefaultAppPool"
Posted
Updated 16-May-12 10:55am
v3
Comments
Wendelius 16-May-12 16:01pm    
Do you get an exception? If you do, what does it say?
Zoltán Zörgő 17-May-12 0:24am    
According to your update consider the lates sentence of my answer below: create common dedicated domain account for the app pool and grant right in dbms (if you are in a domain), or create dedicated sql user and forget the integrated authentication.

Based on the connection string my first guess would be that your workstation is blocking the communication with the SQL Server. If this is for example SQL 2005, use the Surface Area COnfiguration to enable TCP/IP communication from outside your PC. Also check that the firewall in Windows doesn't block the communication

One good checklist to go through: How to configure SQL Server 2005 to allow remote connections[^]

Also check that your ASP.NET service is run under an account that has an access to the SQL Server.
 
Share this answer
 
v2
Comments
VJ Reddy 16-May-12 19:49pm    
Good answer. 5!
Wendelius 17-May-12 4:22am    
Thanks :)
Sandeep Mewara 17-May-12 1:15am    
Good answer. 5!
Wendelius 17-May-12 4:22am    
Thanks :)
The problem is generated by the integrated security setting you use. When you run your application under VS, it runs under your account. I suppose you are admin, thus you have access to the database. But on the server it runs under an account associated with the app pool. The defauls is "network services" You can grant access on the database to the service account, but better you create a dedicated account, that runs your app under iis, and is registered under the sql server, and granted proper rights (not more than necessary).
Update: you cannot grant rights to the service, since it is on a different machine. Create dedicated domain account if you are in a domain or use SQL authentication.
 
Share this answer
 
v4
Comments
VJ Reddy 16-May-12 19:50pm    
Good answer. 5!
Sandeep Mewara 17-May-12 1:15am    
Yes. 5!
Wendelius 17-May-12 4:31am    
Good advice
Zoltán Zörgő 17-May-12 11:54am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900