0

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jazza1000
  • 4,099
  • 3
  • 44
  • 65
  • take a look here in regard to connection strings and how to format them [C# connectionsStrings](http://www.connectionstrings.com) `fyi` connecting to sql server using `SqlDataClient` and connecting to Sql Server via `EF` the connection strings are not the same – MethodMan Feb 24 '15 at 14:59
  • My connection string works fine with my account, but not as local system account – jazza1000 Feb 24 '15 at 15:04

1 Answers1

0

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.

Seymour
  • 7,043
  • 12
  • 44
  • 51
  • Well I could do that, but just wondered why it wouldn't work as the local system user. SQLExpress doesn;t have any issues with it. I could also run as a sql account, but these are workarounds – jazza1000 Feb 24 '15 at 15:00
  • The following article seems to provide a comprehensive overview of options: http://stackoverflow.com/questions/26597498/using-sql-localdb-in-a-windows-service – Seymour Feb 24 '15 at 15:21