![](/img/trans.png)
[英]C# - Visual Studio - Can't connect to cPanel database (remote)
[英]Can't connect to local database using C# Visual Studio
我是數據庫的新手,但是我一直在關注一些教程,但是我一直試圖使用在Visual Studio中創建的精簡版來連接到數據庫。
我正在嘗試通過以下方式連接到數據庫:
string connection = "Data Source=C:/Users/PLOW/Documents/Visual Studio 2012/Projects/File Name/File Name/Users.sdf";
// Making SQL connection
SqlConnection cn = new SqlConnection(connection);
cn.Open();
這樣做我得到此錯誤:
“建立與SQL Server的連接時發生與網絡相關或特定於實例的錯誤。找不到服務器或無法訪問服務器...”
我試過了:
string connection = @"Data Source=|DataDirectory|\Users.sdf";
和我得到同樣的錯誤。 我目前不知道如何連接。
這是我的連接字符串:
由於您使用的是精簡版,因此此處不需要SqlConnection
對象,而應使用SqlCeConnection
並添加對System.Data.SqlServerCe
引用。
使用SqlCeCommand
而不是SqlCommand
如果是連接字符串問題,則必須聲明必需的參數以生成連接字符串
Data Source=servername;Initial Catalog=DbName;Integrated Security=True;User ID=userName;Password=password
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.