C # Connecting to a local DBF MDF file

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

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

Does this mean that I have to install SQL Server 2005 on my computers other than dev? Is there another way?

My connection string:

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

+3
source share
3 answers

The connection string tells the ADO.NET provider of its own Sql Server client to try to connect to an Sql server instance called SQLEXPRESS that will manage the database stored in the DB.mdf file . Since Sql Server Express is not installed on your client computer, it will not look for a database to connect to.

You will need:

  • Sql Server .
  • Sql Server Compact Edition (SqlCE - ) ( SqlCE).
  • ADO.NET DataSets, / DataSet Xml ( WriteXml() ReadXml()). , , , DataSets - ( ) .
+1

/, SQL Server ( .mdf) SQL Server Express.

, /, .

+2

, MS-SQL (Express), . , .

It's not so difficult to include SQl Express in Setup.exe (see PreRequisites).

An alternative is to use SQL-CE or Sqlite or (even) MS-Access. They are “embedded” databases, so you only need to distribute the DLLs.

+1
source

Source: https://habr.com/ru/post/1762176/


All Articles