Ian Warburton
Ian Warburton

Reputation: 15676

How to connect to SQL Server 2000 from .net 4

Here's my connection string...

Data Source=MYMACHINE\SERVER2000; Initial Catalog=MyDatabase; User Id=sa; Password=p;

Here's the 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 can connect fine with Enterprise Manager. Also I have upgraded the SQL Server to Serivce Pack 4.

Any ideas what the issue might be?

Upvotes: 1

Views: 412

Answers (2)

Damon
Damon

Reputation: 3012

I'd suggest testing your connection string using a .UDL file. I've answered a similar question here. After creating your connection, you can rename the extension of the file to .txt, open it and then copy and paste the working connection string in.

Upvotes: 1

Muhammad Essa
Muhammad Essa

Reputation: 142

string connectionString=@"Data Source=MYMACHINE\SERVER2000; Initial Catalog=MyDatabase; User Id=sa; Password=p;";
SqlConnection connection=new SqlConnection(connectionString);
SqlCommand command = new SqlCommand("Select * From Table",connection);
SqlDataReader reader= command.ExecuteReader();

GridView1.DataSource=reader;
GridView1.DataBind();

Use this.... this may help you?

Upvotes: 0

Related Questions