Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
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:
 
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 16-May-12 10:59am
Edited 16-May-12 11:55am
v3
Comments
Mika Wendelius at 16-May-12 16:01pm
   
Do you get an exception? If you do, what does it say?
Zoltán Zörgő at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
VJ Reddy at 16-May-12 19:49pm
   
Good answer. 5!
Mika Wendelius at 17-May-12 4:22am
   
Thanks :)
Sandeep Mewara at 17-May-12 1:15am
   
Good answer. 5!
Mika Wendelius at 17-May-12 4:22am
   
Thanks :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
v4
Comments
VJ Reddy at 16-May-12 19:50pm
   
Good answer. 5!
Sandeep Mewara at 17-May-12 1:15am
   
Yes. 5!
Mika Wendelius at 17-May-12 4:31am
   
Good advice
Zoltán Zörgő at 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)

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 Raul Iloc 170
4 Maciej Los 164
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 16 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100