views:

577

answers:

2

i created an asp.net website with visual studio 2008 sp1 and in the code i use sql connection to reach a data base in my sql server 2008. it all wiorks great but then i wanted to deploy the website in iis7 (windows 7) which was hell to discover how to do it- ( i added a virtual directory and converted it to an application and only then it didn't show me the error that i was getting before i copied it to inetpub\wwwroot and converted it to an application).after doing it i tried to run it from the iis7 but it just keeps showing me an error that it gets in the command sqlconnection.open() which works great when i run the website from the visual studio- so how do i resove this?

i am using the following connection string: "Data SourceEDI-PC\SQLEXPRESS;Initial Catalog=SyncMaster;Integrated Security=True"

and my iis7 is on the same computer as the sql server- so what exextly do i have to do to make it work?

+1  A: 

Your connection string probably looks like this...

<add name="ConnectionString" 
     connectionString="Data Source=servername;
                      Initial Catalog=dbname;
                      Integrated Security=True"
     providerName="System.Data.SqlClient" />

Which means it is using the windows account IIS runs under, NETWORK SERVICE, to connect. When you run from Visual Studio it uses your windows account which has access to the SQL server.

Create a sql user to use as a service account and specify that info in the connection string. This way it will try to connect using the same account that you created in both Visual Studio and IIS.

ie.

<add name="ConnectionString" 
     connectionString="Data Source=servername;
                       Initial Catalog=dbname;
                       Persist Security Info=True;
                       User ID=sqluser;
                       Password=sqruserpassword"
     providerName="System.Data.SqlClient" />
ctrlShiftBryan
A: 

When running in IIS7 (or any other IIS for that matter) the connection to sql server is made as the user that runs the application pool in iis. In IIS7 this is usually NETWORK SERVICE. So if you are using integrated security, you need to grant this account access to the database. If your SQL server instance is running on another machine, say SQLSERVER01, and your web app is running on your machine, YOURMACHINE, then the NETWORK SERVICE account on your machine will be called YOURMACHINE$ as seen by SQLSERVER01.

klausbyskov