Richard Hardy
Richard Hardy

Reputation: 51

SQL Server 2008 Connection String Help Required

I have inherited an ASP.NET project containing a connection string with the DataSource set to:

"Data Source=.\\\sql2008"

I have not seen anything of this type before. Can anyone explain what the .\\\ means? Also, what is the correct technical term for the part set to sql2008?

Thanks very much.

Upvotes: 1

Views: 531

Answers (4)

Aheho
Aheho

Reputation: 12821

The period (.) indicated sql server is running on the same box as the asp.net application.

My hunch is the connection string you posted was pulled out of a c# string literal. The \\ is really just a single slash, but you need to escape it in C# and the escape character is another \.

The sql2008 is the INSTANCE NAME. Sql server can be installed multiple times on a host. The default instance, of which there can be only one, can be reference without the \InstanceName suffix. You can have multiple NAMED INSTANCES. Using the named instance suffix in the connection string is how you designate which instance you are connecting to.

EDIT: If "datasource=sql2008" works then perhaps your server name is sql2008 and your database is installed as the default instance. You can determine if you are using a named instance by inspecting the services control panel applet. If you are using a named instance, the sql service will be listed as "SQL SERVER (MSSQLSERVER$INSTANCENAME)".

Upvotes: 1

Mehdi Bugnard
Mehdi Bugnard

Reputation: 3979

The ". \" always means from the current position in local

In .NET you can escape special characters by either putting an @ in front of the string or using a special value to represent the character you want to escape. In this case you can use \ to represent a \

".\\" == @".\"

So for me

"Data Source=.\\SQLServer2005" equal @"Data Source=.\SQLServer2005"

but

"Data Source =.\\SQLServer2005" or "Data Source =.\\\SQLServer2005"

I do not see what that could mean ...

Do you can try this ?

        SqlConnection cnn ;
        String connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password" 
        cnn = new SqlConnection(connetionString);
        try
        {
            cnn.Open();
            MessageBox.Show ("Connection Open ! ");
            cnn.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Can not open connection ! ");
        }

Lexique:

Data Source : Sql server address,attention if it concerns an instance "SQL EXPRESS" -> please add ..myadress..\SQLEXPRESS

Initial Catalog: DataBase name from your sql server

UserId: User account created on sql server to access the database defined

Password: it's password ^^

Upvotes: 0

Silvia Parfeni
Silvia Parfeni

Reputation: 528

Hello I use this so if this will help you:

Data Source= server_name; Initial Catalog=database_name; User ID=user_id;Password=password

or try to do so:

Server=.\server_name;Database=database_name; User ID=user_id;Password=password

Upvotes: 0

AGB
AGB

Reputation: 2448

This refers to a local instance of sql server running upon the machine that the application is deployed upon. sql2008 is the name of the sql server that is being connected to.

Upvotes: 0

Related Questions