2015-05-09 84 views
0

我有一個數據庫連接到SQL Server使用c + +。我試圖連接到我在SQL Server Management Studio中創建的localdb實例,並且數據庫的名稱是「filingdb」,服務器是「(localdb)\ filing」。我從其他站點複製代碼,並試圖查詢,這是我現在面臨的問題是在這裏,因爲我有共同的錯誤列表:連接到本地數據庫(SQL Server)在c + +

Error 8 error C2440: '=' : cannot convert from 'System::Data::SqlClient::SqlCommandBuilder *' to 'System::Data::SqlClient::SqlCommandBuilder ^' 143 1 cvtest 
Error 6 error C2440: '=' : cannot convert from 'System::Data::SqlClient::SqlDataAdapter *' to 'System::Data::SqlClient::SqlDataAdapter ^' 139 1 cvtest 
Error 4 error C2440: 'initializing' : cannot convert from 'System::Data::DataSet *' to 'System::Data::DataSet ^' 126 1 cvtest 
Error 2 error C2440: 'initializing' : cannot convert from 'System::Data::SqlClient::SqlConnection *' to 'System::Data::SqlClient::SqlConnection ^' 125 1 cvtest 
Error 3 error C2750: 'System::Data::DataSet' : cannot use 'new' on the reference type; use 'gcnew' instead 126 1 cvtest 

System::Data::SqlClient::SqlCommandBuilder'這是我面臨的

的重大課題

我曾嘗試其他方法太多,但我仍然得到同樣的錯誤

Error 12 error C2440: '=' : cannot convert from 'System::Data::SqlClient::SqlCommandBuilder *' to 'System::Data::SqlClient::SqlCommandBuilder ^' 140 1 cvtest 
Error 10 error C2440: '=' : cannot convert from 'System::Data::SqlClient::SqlDataAdapter *' to 'System::Data::SqlClient::SqlDataAdapter ^' 136 1 cvtest 
Error 6 error C2440: 'initializing' : cannot convert from 'System::Data::DataSet *' to 'System::Data::DataSet ^' 126 1 cvtest 
Error 3 error C2440: 'initializing' : cannot convert from 'System::Data::SqlClient::SqlConnection *' to 'System::Data::SqlClient::SqlConnection ^' 125 1 cvtest 
Error 5 error C2750: 'System::Data::DataSet' : cannot use 'new' on the reference type; use 'gcnew' instead 126 1 cvtest 
Error 11 error C2750: 'System::Data::SqlClient::SqlCommandBuilder' : cannot use 'new' on the reference type; use 'gcnew' instead 140 1 cvtest 
Error 2 error C2750: 'System::Data::SqlClient::SqlConnection' : cannot use 'new' on the reference type; use 'gcnew' instead 125 1 cvtest 
Error 9 error C2750: 'System::Data::SqlClient::SqlDataAdapter' : cannot use 'new' on the reference type; use 'gcnew' instead 136 1 cvtest 

任何一個可以請提供關於如何解決這個問題,連接任何其他方法的意見,並可以在任何一個SUG爲未來使用SQL Server註冊連接數據庫而創建任何良好的鏈接?

+1

請告訴我們您的連接字符串和代碼)。 –

回答

0

作爲回答您的需要連接字符串:

的LocalDB(SQL Server 2012中):

的LocalDB命名實例:

Server=(localdb)\MyInstance;Integrated Security=true; 

如果要連接到本地SQL Server,可以使用「.」而不是「IP」或服務器名稱。

0

通過對你有錯誤信息,當您創建任何託管對象的猜測,你必須使用gcnew,即:

System::Data::SqlClient::SqlCommandBuilder^ cmdBuilder = gcnew System::Data::SqlClient::SqlCommandBuilder();