我試圖連接到使用下面的代碼示例數據庫羅斯文在SQL Server 2005 Express的通過Visual C++ 2008連接到SQL Server數據庫:使用Visual C++
SqlConnection^ con=gcnew SqlConnection();
con->ConnectionString="Data Source=localhost\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI";
SqlCommand^ com=gcnew SqlCommand();
com->Connection=con;
com->CommandText="Select * From Customers";
try
{
con->Open();
SqlDataReader^ myReader;
myReader=com->ExecuteReader();
myReader->Read();
Console::WriteLine(myReader->GetData(5));
myReader->Close();
}
catch(Exception^ e)
{
Console::WriteLine(e->Message);
}
finally
{
con->Close();
}
但我得到不同的是
登錄到數據庫失敗,用戶PC-ANKIT
並在此之後,我不知道發生了什麼,但各表數據庫神奇消失。 SQL Server Management Studio中的數據庫列表仍顯示Northwind數據庫,但不包含任何表,視圖或任何內容。另外,當我嘗試在Visual Web Developer 2008 Express版本中使用VB中的等效代碼做同樣的事情時 - 不出現任何問題!我能夠連接到數據庫並訪問所有表中的數據。
任何人都可以幫我解決這個問題嗎?提前致謝!
感謝您的回答!但我仍然不明白爲什麼我以前使用的連接字符串在VC++的情況下不起作用,因爲它在Visual Web Developer中使用時起作用 – ankit0311 2012-02-29 04:13:40