0

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.com Commented Mar 19, 2013 at 23:03

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

I've added connection string I use. Could you please look at it?
@user1876232 please take out the attachdbfilename, user instance and multipleActiveResultSets nonsense and try again.
I'm using service=based database and db file stored with my app files. So I think I cannot take it out from connection string. Also I have this connection string generated automatically when I added Service-Based database item and linked to it with EntityFramework.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.