Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top