Malcolm
Malcolm

Reputation: 12874

Using Linq-to-Sql with SQL Server 2008 R2

I have created some Linq-to-SQL classes object in VS2008 for SQL Server 2008 R2 fine.

I added a connection to it in server explorer. Then add a stored proc to design surface.

But when I run the app it produces this error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

I have enabled TCP/IP and Named Pipes for remote connections according to a googled blog.

Upvotes: 0

Views: 1026

Answers (2)

Adam Rackis
Adam Rackis

Reputation: 83376

Go into your designer file, look in the properties, and find the connection string your designer is using.

Then dig into your dbml file, find the config setting the default constructor of your DataContext is using, and make sure that connection string that setting has is the same as the one from your designer.

Here's where you can find the designer's connection info:

enter image description here

And this is what my default constructor looks like:

    public DataClasses1DataContext() : 
            base(global::Junk.Properties.Settings.Default.ZoomieRestConnectionString, mappingSource)
    {
        OnCreated();
    }

Upvotes: 1

Pankaj Upadhyay
Pankaj Upadhyay

Reputation: 13594

Since you haven't provided the code, its presumably hard to think what going wrong underneath. Anyways here is the code for Linq to SQL connection. Match it with yours

SqlConnection dataConnection = new SqlConnection();
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "YourSeverName";
builder.InitialCatalog = "YourDatabase";
builder.IntegratedSecurity = true;
dataConnection.ConnectionString = builder.ConnectionString;

Upvotes: 0

Related Questions