简体   繁体   English

连接到SQL Server时,数据源的值是什么?

[英]When connecting to SQL Server what are the values for the datasource?

Basically I'm developing a website using ASP.NET MVC4, when creating a model, I need to establish a connection to the database first 基本上,我正在使用ASP.NET MVC4开发网站,在创建模型时,我需要先建立与数据库的连接

When I selected the database name 7CH3LM1 (default in the drop down list), it said: 当我选择数据库名称7CH3LM1 (下拉列表中的默认名称)时,它说:

cannot connect to the database 无法连接到数据库

but when I wrote like 7CH3LM1\\SQLEXPRESS , it let me through 但是当我写类似7CH3LM1\\SQLEXPRESS ,它让我通过了

That reminded me of a question: what's the real difference behind that? 那使我想起了一个问题:其背后的真正区别是什么? what's the meaning of 7CH3LM1 and what's the point adding the SQLEXPRESS ? 7CH3LM1的含义是什么?添加SQLEXPRESS什么意义?

Any ideas are very welcomed! 任何想法都非常欢迎!

7CH3LM1 is your machine name, and it helps identify the instance of SQL Server you're connecting to. 7CH3LM1是您的计算机名称,它有助于标识您要连接的SQL Server 实例 In this case, you are connecting to a named instance of SQL Server running Express Edition, and its instance name is SQLEXPRESS . 在这种情况下,您将连接到运行Express Edition的SQL Server的命名实例,其实例名称为SQLEXPRESS A machine can run multiple instances of SQL Server concurrently, and it can have one default instance and 0, 1 or multiple named instances. 一台计算机可以同时运行多个SQL Server实例,并且可以具有一个默认实例和0、1或多个命名实例。 To connect to the default instance, you would use 7CH3LM1 , and to connect to a named instance, you would use 7CH3LM1\\<instance name> , as you have with 7CH3LM1\\SQLEXPRESS . 要连接到默认实例,将使用7CH3LM1 ,而要连接到命名实例,则将使用7CH3LM1\\<instance name> ,就像使用7CH3LM1\\SQLEXPRESS

I typically rename my machines to something a little more memorable and meaningful, as that can make things much easier, but that's just me. 我通常将机器重命名为更容易记忆和有意义的名称,因为这可以使事情变得更加容易,但这就是我自己。

An instance of SQL Server can contain many databases . SQL Server 实例可以包含许多数据库 You can specify the database in your connection string as well (recommended), or you can rely on your login's default database to define initial context (not recommended, since that database could be offline, single user, detached, etc. - which will affect your ability to log in). 您也可以在连接字符串中指定数据库(推荐),或者可以使用登录名的默认数据库来定义初始上下文(不建议使用,因为该数据库可能是脱机的,单用户的,分离的等等),这会影响您的登录能力)。

Ultimately, your software will need both an instance and a database in order to read / write data. 最终,您的软件将需要一个实例和一个数据库才能读取/写入数据。

You're talking about an INSTANCE name. 您在说的是INSTANCE名称。 Multiple instances of SQL servers can exist on the same machine. 同一台计算机上可以存在多个SQL Server实例。 If you do not specify the instance, you will connect to the DEFAULT instance of SQL server on the machine (which may or may not exist.) When you do specify one (after the "\\"), it's known as a NAMED instance. 如果不指定该实例,则将连接到计算机上SQL Server的DEFAULT实例(该实例可能存在或可能不存在。)当您指定一个实例(在“ \\”之后)时,该实例称为NAMED实例。

You can read more about instances, here: msdn.microsoft.com/en-us/library/hh231298.aspx 您可以在此处阅读有关实例的更多信息: msdn.microsoft.com/en-us/library/hh231298.aspx

In summary, syntax for selection of instance on MSSQL servers is expressed as 总之,用于在MSSQL服务器上选择实例的语法表示为

SERVERNAME\INSTANCENAME

or for the DEFAULT instance: 或对于DEFAULT实例:

SERVERNAME

And, personally, I think the docs for SQL 2000 are much easier to read about DEFAULT vs. NAMED instances. 而且,就我个人而言,我认为SQL 2000的文档更容易阅读有关DEFAULT与NAMED实例的信息。 You can find them here: http://msdn.microsoft.com/en-us/library/aa174516(v=sql.80).aspx 您可以在这里找到它们: http : //msdn.microsoft.com/zh-cn/library/aa174516(v=sql.80).aspx

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

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