什么是与AttachDbFilename问题 [英] what's the issue with AttachDbFilename
问题描述
显然,使用 AttachDbFilename
和用户实例
是一个糟糕的方式连接到数据库。我用我的本地机器上的SQL Server EX preSS,这一切似乎很好地工作。但是,什么是正确的方式连接到SQL Server将?
Apparently, using AttachDbFilename
and user instance
in your connection string is a bad way to connect to a DB. I'm using SQL server express on my local machine and it all seems to work fine. But what's the proper way to connect to SQL server then?
感谢您的解释。
推荐答案
使用用户实例
意味着SQL Server正在创建数据库文件的一个特殊的副本通过使用您的程序。如果你有使用相同的连接字符串两个不同的程序,他们得到的数据库的两个完全不同的副本。这导致的很多的混乱,因为人们将考验他们的程序更新数据,然后连接到他们Management Studio中的数据库不同的副本,并抱怨自己的更新不能正常工作。这会将他们通过一个有缺陷的一系列尝试解决错误的问题徒劳无益的步骤。
Using User Instance
means that SQL Server is creating a special copy of that database file for use by your program. If you have two different programs using that same connection string, they get two entirely different copies of the database. This leads to a lot of confusion, as people will test updating data with their program, then connect to a different copy of their database in Management Studio, and complain that their update isn't working. This sends them through a flawed series of wild goose chase steps trying to troubleshoot the wrong problem.
本文进入有关如何使用此功能更深入但注意的第一注:的用户实例
功能已经去precated 。在SQL Server 2012中,preferred替代品(按照这个顺序,恕我直言):
This article goes into more depth about how to use this feature, but heed the very first note: the User Instance
feature has been deprecated. In SQL Server 2012, the preferred alternatives are (in this order, IMHO):
-
创建或附加数据库到SQL Server的一个真实的实例。然后,您的连接字符串将只需要指定实例名,数据库名称和凭据。不会有任何查询股价为Management Studio中,Visual Studio和你的程序(S)都将连接到数据库的一个副本。
Create or attach your database to a real instance of SQL Server. Your connection string will then just need to specify the instance name, the database name, and credentials. There will be no mixup as Management Studio, Visual Studio and your program(s) will all be connecting to a single copy of the database.
使用 SqlLocalDb
为当地的发展。我相信我昨天指出你的这篇文章:<一个href=\"http://www.mssqltips.com/sqlservertip/2694/getting-started-with-sql-server-2012-ex$p$pss-localdb/\"相对=nofollow>入门与SQL Server 2012前preSS的LocalDB 。
Use SqlLocalDb
for local development. I believe I pointed you to this article yesterday: "Getting Started with SQL Server 2012 Express LocalDB."
当然,如果你使用的是版本&LT; SQL Server 2012中, SqlLocalDb
是不是一种选择 - 所以你应该建立一个真正的数据库,并使用该一致。我只提的完整性紧凑选项 - 我认为这几乎可以作为一个坏主意,因为使用 AttachDbFileName
Of course if you are using a version < SQL Server 2012, SqlLocalDb
is not an option - so you should be creating a real database and using that consistently. I only mention the Compact option for completeness - I think that can be almost as bad an idea as using AttachDbFileName
.
编辑:我的博客上讲述这个位置:
I've blogged about this here:
- Bad Habits : Using AttachDBFileName
这篇关于什么是与AttachDbFilename问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!