What is the problem with AttachDbFilename

Apparently, using AttachDbFilenameand user instancein your connection string is a bad way to connect to the database. I am using SQL Server express on my local machine and it all works fine. But how to connect to the SQL server?

Thanks for your explanation.

+5
source share
2 answers

Use User Instancemeans that SQL Server creates a special copy of this database file for use by your program. If you have two different programs using the same connection string, they get two completely different copies of the database. This leads to a lot of confusion, as people will test the data update with their program, and then connect to another copy of their database in Management Studio and complain that their update does not work. This sends them through an erroneous sequence of wild geese steps trying to fix the problem.

This article describes in more detail how to use this function , but listen to the very first note: the function is deprecated . In SQL Server 2012, the preferred alternatives are (in that order, IMHO): User Instance

, < SQL Server 2012, SqlLocalDb , . Compact - , , AttachDbFileName.

: :

+11

- .

, AttachDBFile SQLEXPRESS, , ASP.NET, . , System.Data.SqlClient .

DataBase, :

Data Source=.\SQLEXPRESS;DataBase=PlaCliGen;User ID=XXX;password=ZZZ; Connect Timeout=30 

PlaCliGen - ( ), SQLEXPRESS .

AttachDBFile, .mdf (namely : replacing DataBase = PlacliGen by AttachDBFile = c:\vs\placligen\app_data\placligen.mdf) , .

-1

All Articles