Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server connection string specified without a computer name? How can that be?

I'm working from a code base I downloaded from a repository, and it is likely that I'm missing a system or local setting.

In Web.Config, I have this connection string:

<add name="Context" 
    connectionString="Data Source=InstanceName;
        Initial Catalog=MyProduct;
        Integrated Security=True;
        Connect Timeout=15;
        Encrypt=False;
        TrustServerCertificate=False"
    providerName="System.Data.SqlClient" />

(indentation mine)

Normally I would have expected the Data Source to be \\ComputerName\InstanceName or at least .\InstanceName if the SQL Server is on the same host. But here, nothing. The initially uploaded project had a local database, on the developer's machine. I can get the connection to work if I add .\, but I don't understand how only specifying the instance name can work. So, how can it?

like image 475
MPelletier Avatar asked Apr 21 '14 00:04

MPelletier


2 Answers

The instance name is needed only if you want to connect to a named instance.
If your install of Sql Server hasn't created a named instance then the default for the instance is MSSQLSERVER and you DON'T need to specify that part on the connection string.

However, the computer name part is required but it could be expressed in various form

  1. a point to mean the local computer
  2. an IP address (local or not)
  3. a server name recognized by the DNS system of your lan
  4. the special string (LOCAL)

More info on the Data Source key could be found on MSDN docs for ConnectionString

like image 56
Steve Avatar answered Sep 22 '22 03:09

Steve


Could it be that the InstanceName is the name of an ODBC Data Source that already has the target server configured, and the other employees have a corresponding ODBC data source set up?

The other option is that the connectionstring is modified before being passed to a data connector, so "MyMachineName" + connectionstring is happening somewhere (perhaps to separate production and development environments?

Also, double check the App_Data folder to make sure some sort of file-based database isn't being accessed.

like image 23
Richthofen Avatar answered Sep 19 '22 03:09

Richthofen