5

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?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
  • in your actual connection string is the server name being used as the InstanceName? The reason I asked this is because when you are connecting to the default instance of sql server you can simply use the machine(Server) name to connect to sql server, but if you are trying to connect to a named instance of sql server then you have to use the full MachineName\InstanceName . – M.Ali Apr 21 '14 at 00:17
  • @M.Ali So, you're saying the only way the above could work would be if MachineName == InstanceName? – MPelletier Apr 21 '14 at 00:20
  • No only if MachineName == Default Instance Name which is `MSSQLSERVER` – M.Ali Apr 21 '14 at 00:21
  • @M.Ali Ah! Could be that's what the original machine is called. I'll check (Tuesday) and report back. – MPelletier Apr 21 '14 at 00:25
  • @M.Ali Confound it, they're not. However, MachineName == InstanceName (non-case sensitive). My colleague claims he hasn't done anything special, it's an "out of the box" setup. – MPelletier Apr 22 '14 at 13:12
  • Yes out of the box setup means it has used the default instance name for sql server instance name i.e `MSSQLSERVER`, And the machine/Server is also called `MSSQLSERVER`. – M.Ali Apr 22 '14 at 14:15
  • @M.Ali Except the instance name in my case is not `MSSQLSERVER` at all. – MPelletier Apr 22 '14 at 14:52
  • are there aliases set up on the server? cliconfg.exe – Bozman Apr 22 '14 at 17:50

3 Answers3

6

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

Steve
  • 213,761
  • 22
  • 232
  • 286
1

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.

Richthofen
  • 2,076
  • 19
  • 39
0

In addition to what @Steve has already mentioned local or current machine can also be referred by a special string localhost. Please refer to below post:

What is the sql connection string I need to use to access localhost\SQLEXPRESS with Windows Authentication or SQL Authentication?

RBT
  • 24,161
  • 21
  • 159
  • 240