0
votes

I have a WCF Service which is hosted in a windows service, and when it connects to the localdb database it produces 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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist

This is my connection string:

<add name="CredentialEntities" 
     connectionString="metadata=res://*/Credential.csdl|res://*/Credential.ssdl|res://*/Credential.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=(localdb)\projects;Initial Catalog=Credentials;Integrated Security=True&quot;" 
     providerName="System.Data.EntityClient" />

I can connect to this database via SQL Server Management Studio no problem, and I can also connect via Visual Studio data connections to the data source. When I run the windows service as my account it works successfully.

I have tried adding the NT AUTHORITY\SYSTEM account as a sysadmin in SQL Server, but no luck

1
take a look here in regard to connection strings and how to format them C# connectionsStrings fyi connecting to sql server using SqlDataClient and connecting to Sql Server via EF the connection strings are not the same - MethodMan
My connection string works fine with my account, but not as local system account - jazza1000

1 Answers

0
votes

Suggest you consider adding a user for dedicated database access (e.g. myServiceUser) and then set the new user as the Windows Service account. Finally, add the necessary SQL server permissions to allow the dedicated SQL Server access user account to query the target views and call the related procedures.