简体   繁体   English

SQL Server express和SQL Server的连接字符串有什么区别吗?

[英]Is there any difference between connection string for SQL server express and SQL server?

In my application, i make a dynamic connection string: 在我的应用程序中,我创建一个动态连接字符串:

server = "Server  = .\\" + this.comboBoxListInstances.SelectedItem.ToString() + ";";
connectionString = server + attachDatabase + databaseName + "Integrated Security = true";

On my laptop (using SQL server 2008 express), the result is: 在我的笔记本电脑上(使用SQL Server 2008 express),结果是:

// server = "Server = .\\SQLEXPRESS;" (I select SQLEXRESS in comboBox)
// attachDatabase = "AttachDbFileName = |DataDirectory|\\Resources\\DT.mdf;"
// databaseName = "Database = DATA;";
// so the conectionString is : "Server = .\\SQLEXPRESS;AttachDbFileName = |DataDirectory|\\Resources\\DT.mdf;Database = DATA;Integrated Security = true"

I read registry to find all SQL server Instances and let the user choose which they want. 我读了注册表来查找所有SQL服务器实例,让用户选择他们想要的。
This conectionString work fine on my laptop and my friend who use SQL server express too. 这个conectionString在我的笔记本电脑和我的朋友使用SQL服务器表达也很好。 However, when i run my app on another friend's laptop with SQL server 2008 R2 installed, it throws an exception: 但是,当我在安装了SQL Server 2008 R2的另一位朋友的笔记本电脑上运行我的应用程序时,它会引发异常:

在此输入图像描述

It say the connection string is invalid, It is : 它说连接字符串无效,它是:

"Server = .\\MSSQLSERVER;AttachDbFileName = |DataDirectory|\\Resources\\DT.mdf;Database = DATA;Integrated Security = true"

when I try to temporarily disable comboBoxListInstance and use this conectionString 当我尝试暂时禁用comboBoxListInstance并使用此conectionString时

"Server = (local);AttachDbFileName = |DataDirectory|\\Resources\\DT.mdf;Database = DATA;Integrated Security = true"

The app works! 该应用程序工作! So, I think there is a difference between the conection string for SQL server express and SQL server. 所以,我认为SQL Server express和SQL Server的连接字符串之间存在差异。 Is it right? 这样对吗? There is a question similar to mine here , and they say that there is no difference. 有类似地雷问题在这里 ,他们说,没有什么区别。 If they are right, what is the problem of my connectionString? 如果他们是对的,我的connectionString有什么问题?

P/S: sorry for my bad grammar P / S:抱歉我的语法不好

It looks like you just proved that SqlExpress installs its default named instance as "MSSQLSERVER" where as full sql installs an unnamed default instance of blank. 看起来您刚刚证明SqlExpress将其默认命名实例安装为“MSSQLSERVER”,其中完整的sql安装了一个未命名的默认空白实例。

(local) means " .\\ " " 127.0.0.1" WHATEVER instance is at 1433. (local)表示“。\\”“127.0.0.1”WHATEVER实例是1433。

.MSSQLEXPRESS means explicitly .\\MSSQLEXPRESS which may or may not be the (local) default instance. .MSSQLEXPRESS明确表示。\\ MSSQLEXPRESS可能是也可能不是(本地)默认实例。

As An Aside usually the most relevant difference at this point is that regular SQL will install with the ports open and TCP clients ready to go. 作为An Aside,通常在这一点上最相关的区别是常规SQL将在端口打开并且TCP客户端准备好的情况下安装。

SQL Express will only allow local "dev" type of connections until you activate the external ports and client protocols. 在您激活外部端口和客户端协议之前,SQL Express将仅允许本地“dev”类型的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM