我是Visual C#的新手。 (我來自javaland)無法從C#連接到SQL Server Compact#
我使用IDE的Data -> Add New Data Source
工具來創建我的應用程序可以連接的數據庫。 我可以從IDE的數據庫瀏覽器打開數據庫,但是我無法連接到應用程序的 數據庫。
該數據庫是一個沒有密碼或加密的SQL Server Compact 3.5文件。這是自動生成的連接字符串:
Data Source=|DataDirectory|\test.sdf
但是當我運行下面的代碼...
SqlConnection con = new SqlConnection("Data Source=|DataDirectory|\\test.sdf");
con.Open();
我得到的錯誤
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)
在con.Open()
;
我在做什麼錯?
感謝您的幫助!
謝謝!現在工作很好。 – DRJTower
絆倒了我大的時間,謝謝。 –
謝謝!這真的幫助了我! –