1

I developed a small project in visual studio 2010. In my project I attach a service-based database named database1.mdf.

My connectionString is :

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True

It works fine on my developer pc but it throws an exception on a client's pc.

Exception is :

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 don't understand what is happening.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Vero009
  • 612
  • 3
  • 18
  • 31

2 Answers2

1

this connection string is for your developer machine. you share your database on the network. you also must update your connection string by adding ip address of your server.

erencan
  • 3,725
  • 5
  • 32
  • 50
  • I am also copy my application.exe and database1.mdf file in the same folder. – Vero009 Nov 13 '11 at 16:58
  • Is sqlserver run on client pc? if so, you try to update your DataDirectory property for your client pc like AppDomain.CurrentDomain.setData(“DataDirectory”,”C:\myDB”); – erencan Nov 13 '11 at 17:06
1

Two things need to occur before you can connect to a SQL Server Express database.

  1. SQL Server Express must be installed on the target server. Having the file present isn't sufficient. (This is what the error you're experiencing likely means).

  2. The path to your database file should be an absolute path to rule out the possibility of a file location error.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Joel Etherton
  • 37,325
  • 10
  • 89
  • 104