0
votes

What connection string should I use if SSMS connects to it using simply machine name, without instance name?

I mean it connects using the following string: PCName

I used to connect using PCName/SQLExpress. I cannot set correct connection string in my app in order to connect app to database on this machine.

How can I check what data source I should use? I've checked in Sql Server configuration that server instance named as SQLEXPRESS.

So I tried data source as: .\SQLEXPRESS PCName\SQLEXPRESS .

I'm trying to connect to a service-based database, located in my app folder. So I'm using the following connection string:

data source=PCName;attachdbfilename=|DataDirectory|\spareparts.mdf;integrated security=true;user instance=true;multipleactiveresultsets=true;App=EntityFramework;

1
Whenever I struggle with connection strings in different environments I check this site and have found it to be very useful. Hope it helps: connectionstrings.combjoern

1 Answers

1
votes

If SSMS connects via PCName then your application should be able to use Data Source=PCName. However it depends on whether your application is on the same machine as SSMS or not. If on a different machine it might not be able to connect for a variety of reasons. We can't speculate what the problem might be if all you do to describe the issue is "It won't connect" - what does that mean? Do you get an error message? If so, what is it? Make sure:

  • SQL Browser service is started
  • TCP/IP is enabled
  • Add Network=DBMSSOCN; to the connection string
  • You've also tried the IP address in addition to PCName
  • Firewall isn't blocking the SQL Server port