连接字符串和附加数据库
我使用将数据库附加到 Visual Studio 2010 中的服务器资源管理器,而不是使用连接到我已安装在电脑上的 sql server 2008。
例子: 我的连接字符串曾经是这样的:
<add name="YourGuruDB"
connectionString="Data Source=DIMA-00AA1DA557;Initial Catalog=model;Integrated Security=True"/>
现在它已更改为这样:
<add name="YourGuruDB"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\Little Rabbit\Desktop\New Folder (2)\YourGuruDB1.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient"/>
我选择连接数据库的方式是否有差异(例如,在性能、安全性或舒适度方面)?
I use to attach a database to my server explorer in visual studio 2010, instead of using a connection to sql server 2008 which i have installed on my pc.
Example:
My connection string used to be this:
<add name="YourGuruDB"
connectionString="Data Source=DIMA-00AA1DA557;Initial Catalog=model;Integrated Security=True"/>
And now it has changed to this:
<add name="YourGuruDB"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\Little Rabbit\Desktop\New Folder (2)\YourGuruDB1.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient"/>
Is there a difference in the way I choose to connect a database (on performance or security or comfort, for example)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的第一个连接字符串使用 SQL Server(Express 或其他版本)作为服务器 - 服务器始终运行,您的客户端只是使用符号名称(对于服务器和数据库)连接到它。
在第二个示例中,您仅限于 SQL Server Express 版本 - 此方法不适用于任何其他版本。另外:当您连接时,您正在“启动并附加”一个 SQL Server Express 实例 --->听起来这可能会花费相当长的时间,至少在第一次点击时是这样。而且:现在您的客户突然必须处理 .MDF 文件和类似内容的存在......
就个人而言,我总是使用基于服务器的方法 - 或者如果您确实需要本地客户端计算机上的数据库,请改用 SQL Server Compact Edition(使用单个
.sdf
文件)。Your first connection string is using SQL Server (Express or other edition) as a server - the server is running the whole time, your clients are just connecting to it using a symbolic name (for the server and the database).
In your second example, you're limited to the SQL Server Express editions - this approach doesn't work with any other edition. Also: you're "spinning up and attaching" a SQL Server Express instance when you connect ---> sounds like this might take up quite some time, at least during the first hit. And also: now your clients suddenly have to deal with presence of .MDF files and stuff like that.....
Personally, I would always use the server-based approach - or if you really need a database on a local client machine, use SQL Server Compact Edition (using a single
.sdf
file) instead.