I made a web service that connects to a database hosted in SQL Server 2008 R2 on my local computer, and makes some operations on it.
This is the connection string in the web service:
conn = new SqlConnection("Data Source=amir-pc\\SQLEXPRESS;User Id=sa;Password=1234; Initial Catalog=Election;Integrated Security=True");
It works well and successfully accesses the database and runs right.
Now I want to add this web service to IIS.
I successfully added it on Windows 7 to the IIS and can run it from the browser.
localhost/election_service/service.asmx
but when I tried to call a function that checks the connection, it failed, and I don’t know why.
This is the function:
[WebMethod]
public string Check_conn()
{
try
{
conn.Open();
conn.Close();
return "ok";
}
catch
{
return "failed";
}
}
Is there any modification I must to do to be able to access the database?
Hi can you give more information please try change you code for know what is exception is raising.
Hi, then .. is a login issue:Open IIS Open Application Pool Select your current application pool are you current working (by default is DefaultAppPool) Go to Advanced Options, and find Identity and change to (NT AUTHORITY\Network Service) Then you has been changed your application user, now you need to add permision to network service to database Open SQlMananger, then go to Node Security, rigth click and properties go to NT AUTHORITY\Network Service go to User mapping and add the database you want to allow access.