LifeScript
LifeScript

Reputation: 1114

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

When I selected the database name 7CH3LM1 (default in the drop down list), it said:

cannot connect to the database

but when I wrote like 7CH3LM1\SQLEXPRESS, it let me through

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?

Any ideas are very welcomed!

Upvotes: 2

Views: 69

Answers (2)

Lynn Crumbling
Lynn Crumbling

Reputation: 13367

You're talking about an INSTANCE name. Multiple instances of SQL servers can exist on the same machine. 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.

You can read more about instances, here: msdn.microsoft.com/en-us/library/hh231298.aspx

In summary, syntax for selection of instance on MSSQL servers is expressed as

SERVERNAME\INSTANCENAME

or for the DEFAULT instance:

SERVERNAME

And, personally, I think the docs for SQL 2000 are much easier to read about DEFAULT vs. NAMED instances. You can find them here: http://msdn.microsoft.com/en-us/library/aa174516(v=sql.80).aspx

Upvotes: 1

Aaron Bertrand
Aaron Bertrand

Reputation: 280351

7CH3LM1 is your machine name, and it helps identify the instance of SQL Server you're connecting to. In this case, you are connecting to a named instance of SQL Server running Express Edition, and its instance name is 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. 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.

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. 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.

Upvotes: 5

Related Questions