views:

53

answers:

2

On my development computer I have MS SQL Server/Visual Studio 2005. My program can correctly connect to my local DB and use it. However my other computer (non-dev) does not have MS SQL Server/Visual Studio 2005 and does not connect to the DB. It spits out the following:

"An error has occurrred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. ..." (Error: 26).

Does this mean I have to install SQL Server 2005 on my non-dev computers? Is there any other way?

My connection string is:

"Data Source=.\SQLEXPRESS;AttachDbFilename=\"" + Directory.GetCurrentDirectory() + "\DB.mdf\";Integrated Security=True;User Instance=True";

+1  A: 

If you want to run it on that other pc/server you also need to have SQL Server (need to attach your .mdf to it) or SQL Server Express installed.

Another trick would be to change your connection string so that it points out to another pc/server where your database runs on.

XIII
+1  A: 

Your connection string is telling the Sql Server Native Client ADO.NET Provider to attempt to connect to a Sql Server instance named SQLEXPRESS that will manage the database stored in a file DB.mdf. Since your client computer does not have Sql Server Express installed, it's not going to find a database to connect to.

You will need to:

  • Install Sql Server on the client computer and deploy your database there.
  • Switch to Sql Server Compact Edition (SqlCE - embedded database) and re-architect your application to use the portable database file (with SqlCE) instead.
  • Ditch using a robust database engine and switch entirely to ADO.NET DataSets, saving/loading the contents of the DataSet to an Xml file (via WriteXml() and ReadXml()). If the amount of data you are processing is fairly limited in size, DataSets are a good approach to maintaining integrity (via a strongly typed and well-defined schema) and portability.
Michael