2013-12-09 26 views
0

這裏是我的連接字符串連接到SQL Server 2000 ...如何從.NET 4

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

這裏的錯誤....

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)

我可以用企業管理器正常連接。此外,我已將SQL Server升級到Serivce Pack 4.

任何想法可能是什麼問題?

+0

嘗試使用舊式連接字符串:在您的情況下,它會是類似這個:'server = MYMACHINE \ SERVER2000;數據庫= MyDatabase的; UID = SA; pwd = p;' –

回答

1

我建議使用.UDL文件測試您的連接字符串。我已經回答了類似的問題here。創建連接後,您可以將文件的擴展名重命名爲.txt,將其打開,然後複製並粘貼工作連接字符串。

+0

是的,雖然我不得不從字符串中刪除'Provider'屬性,而是將XML元素上的'providerName'更新爲'System.Data.OleDb'。它與ADO.net連接。但Code First不會連接。 –

0
string [email protected]"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(); 

使用此....這可能對您有幫助嗎?