[英]Having problems connecting to SQL Server in C#
我正在嘗試連接到SQL Server。
我正在嘗試在C#中使用SqlConnection
對象,我曾嘗試將域放在用戶名之前,並且嘗試使用和不使用端口號
SqlConnection myConnection = new SqlConnection("user id=username;" +
"password=xxxxx;" +
"server=ipaddress:portnumber;" +
"Trusted_Connection=yes;" +
"database=databaseName; " +
"connection timeout=30");
try
{
myConnection.Open();
}
catch(Exception ex)
{
}
我沒有收到任何錯誤消息,它只是掛在myConnection.Open
您嘗試使用這種格式的連接字符串。 請在C# 鏈接中找到此鏈接以獲取有關連接字符串的更多信息。
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
SqlConnection myConnection = new SqlConnection("Data Source=ipaddress;
Initial Catalog=dbname;
User Id=userid;
Password=pass;");
正如@marc_s在注釋中已經提到的那樣,必須在連接逗號時指定端口號,在這種情況下,它應該類似於server=ipaddress,portnumber;
。
但是, 這些步驟可以幫助您快速解決SQL Server的連接問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.