简体   繁体   English

sql server express连接字符串

[英]sql server express connection string

sql server连接字符串和express vesion之间有区别吗?!

By default (though I don't recommend it 1 ), Sql Express is installed as a named instance . 默认情况下(虽然我不建议1 ),Sql Express作为命名实例安装。 That means you must connect like Server=servername.com\\SQLEXPRESS as opposed to just Server=servername.com . 这意味着您必须连接像Server=servername.com\\SQLEXPRESS而不是Server=servername.com

As always, connectionstrings.com has the goodies. 和往常一样, connectionstrings.com有好东西。

1 I don't recommend named instances because they run on a different port , which makes firewalling a PITA. 1我不建议使用命名实例,因为它们在不同的端口上运行 ,这使得防火墙成为PITA。 Also, it makes little sense to me to run more than 1 MSSQL Server on a computer when you could just host multiple databases instead - so I'm not really sure what the point is. 另外,当你只能托管多个数据库时,在计算机上运行多个MSSQL Server是没有意义的 - 所以我不确定这是什么意思。

The connection string used to access SQL Server and SQL Server Express? 用于访问SQL Server和SQL Server Express的连接字符串?

Generally, no. 一般来说,没有。 That's the nice thing about using Express; 这是使用Express的好处; develop with it locally and with minimal changes migrate your data access to SQL Server. 在本地进行开发,只需极少的更改即可将数据访问迁移到SQL Server。

The only difference is that you'll have to specify a named instance in the conn string, if Express was setup that way. 唯一的区别是,如果以这种方式设置Express,则必须在conn字符串中指定命名实例。 2005 had no option, but 2008 does. 2005年别无选择,但2008年确实如此。

Data Source=localhost\SQLExpress

Here's a great reference for connection strings . 这是连接字符串的一个很好的参考

Yes there is a difference- the big one being you won't have AttachDbFilename in the full SQL Server. 是的,有一点不同 - 最重要的是你不会在完整的SQL Server中使用AttachDbFilename。

SQL Server Express connection string: SQL Server Express连接字符串:

Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;

Typical normal SQL Server connection string: 典型的普通SQL Server连接字符串:

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

See connectionStrings.com for more info. 有关详细信息,请参阅connectionStrings.com

I recently downloaded a sample application from the Telerik site and could not get it to run on my machine that has only SQL Server 2008 SP1 Developer Edition installed until I did a find and replace of all "User Instance=True" with "User Instance=False". 我最近从Telerik网站下载了一个示例应用程序,并且无法让它在我只安装了SQL Server 2008 SP1 Developer Edition的计算机上运行,​​直到我找到并用“User Instance =”替换所有“User Instance = True”假”。

Before anybody goes and gets their panties all twisted in a knot, hear me out first. 在任何人去之前,让他们的内裤全部扭结,请先听我说。 My circumstances may be (but ought not be) unique in that instead of installing SQL Server 2008 Express just to run example applications (eg, Telerik), I simply installed a second named instance of SQL Server named, you guessed it, sqlexpress on my copy of SQL Server 2008 Developer Edition. 我的情况可能是(但不应该)唯一的,因为我只是安装SQL Server 2008 Express来运行示例应用程序(例如,Telerik),我只是安装了第二个命名的SQL Server实例,你猜对了,sqlexpress在我身上SQL Server 2008 Developer Edition的副本。 That way when the Telerik (or you name it) demo application tries to connect to "Data Source=.\\sqlexpress", it's none the wiser that what it's really connecting too is "big SQL Server" (which is what SQL Server Developer Edition is for the purposes of this posting). 这样,当Telerik(或你的名字)演示应用程序试图连接到“Data Source =。\\ sqlexpress”时,它真正连接的是“大SQL Server”(这就是SQL Server Developer Edition)并不明智是为了这个帖子的目的)。

The key conecpts (dare I say "money quote") you need to understand are these: 你需要了解的关键锥形图(我敢说“金钱报价”)是这些:

SQL Express allows (actually assumes if missing) User Instance=True, so if you are running a named instance called sqlexpress on "big SQL" (Developer, Standard, Enterprise or Data Center), then you just need to find/replace User Instance=True with User Instance=False in the connecton string and your worries are over. SQL Express允许(实际上假设如果缺少)User Instance = True,因此如果您在“big SQL”(开发人员,标准,企业或数据中心)上运行名为sqlexpress的命名实例,那么您只需要查找/替换用户实例=如果用户实例= True,则连接字符串中的False,您的后顾之忧已经结束。 Even the "Attach database" stuff (that I see in the Telerik connectionStrings section of their web.config) works on "big SQL" (contrary to what somebody posted earlier in this thread). 甚至“附加数据库”的东西(我在他们的web.config的Telerik connectionStrings部分中看到的)也适用于“大SQL”(与之前在此主题中发布的内容相反)。

Here's an actual example taken directly from the web.config of the Telerik web.config file after I "fixed it up": 这是我在“修复”之后直接从Telerik web.config文件的web.config中获取的实际示例:

<connectionStrings>
    <add name="NorthwindConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Northwind.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
    <add name="TelerikConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Telerik.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
    <add name="NorthwindConnectionString35" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Northwind.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
    <add name="TelerikConnectionString35" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Telerik.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
    <add name="NorthwindEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;User Instance=False;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
    <add name="TelerikEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Telerik.mdf;Integrated Security=True;User Instance=False;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
    <add name="EditorFileBrowserDatabase" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|EditorDBStorage.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient"/>
</connectionStrings>

In addition to previous post: If you have troubles with setup Telerik samples on MSSQL Server 2008, you can do the following: 除了上一篇文章:如果您在MSSQL Server 2008上安装Telerik示例时遇到问题,您可以执行以下操作:

  1. Open LiveDemos Telerik VS solution 打开LiveDemos Telerik VS解决方案
  2. Setup database connections for telerik .mdf files in VS master 在VS master中为telerik .mdf文件设置数据库连接
  3. Copy connection string for connections to the web.config file 复制连接到web.config文件的连接字符串
  4. And add "Integrated Security=True;User Instance=False" to the end of the strings. 并在字符串末尾添加“Integrated Security = True; User Instance = False”。

PS. PS。 Fred Morrison - thanx, you are my "man of day", I just fix Telerik Live Demo problem with you post help! Fred Morrison - thanx,你是我的“日常人”,我只是帮你解决了Telerik Live Demo的问题!

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

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