I have created a class that will connect to SQL Server to run a stored procedure. When this class is used in a Windows Forms solution, the database can be accessed successfully. When the class is put into a Windows Service, I get the following error:
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I suspect the problem is permissions-related.
This is the section of relevent code:
SqlConnection conn = new SqlConnection(j.ConnectionString);
SqlCommand cmd = new SqlCommand(j.Query, conn);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet("Table1");
da.Fill(ds, "Table1"); // <----- error occurs here (Windows Service only)
The SQL Server version is
Microsoft SQL Server 2008 (SP1) - 10.0.2766.0 (X64)
Enterprise Edition (64-bit) on Windows NT 5.2 <X64>
(Build 3790: Service Pack 2)
The Visual Studio version is Microsoft Visual C# 2008
Framework version is 3.5 SP1
.