2013-02-13 19 views
1

我遇到的問題是從ASP.NET應用程序連接到我的SQL Server(2005)上的帳戶。通過字符串連接到SQL服務器時出錯,無法識別用戶名或密碼

我曾嘗試使用默認的sa登錄和用戶ive已創建的SQL管理工作室的設置已設置爲混合屬性,我有在webconfig中的字符串連接,以及也不起作用。

C#代碼

//string conStr = ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString; 
    string conStr = @"server=JAMES-PC\SQLEXPRESS; database=projectDB; uid=james; password=password;"; 
    string query = "SELECT [TaskID], [Task], [Start Date] AS Start_Date, [End Date] AS End_Date, [Priority], [Time Allowance] AS Time_Allowance, [Details], [Catagory] FROM [schedulerData0]"; 
    SqlDataAdapter dataAdapt = new SqlDataAdapter(query, conStr); 
    DataTable table = new DataTable(); 
    dataAdapt.Fill(table); 
    GridView1.DataSource = table; 
    GridView1.DataBind(); 

我收到的錯誤消息是:

用戶登錄失敗 '詹姆斯'。用戶未與可信的SQL Server連接相關聯。

任何幫助表示讚賞 詹姆斯

+1

也許你需要IntegratedSecurity = SSPI? – 2013-02-13 13:47:13

+0

當您使用SQL帳戶時,將IntegratedSecurity = false設置爲 – 2013-02-13 13:48:23

+0

此代碼將在webconfig中的位置?或管理工作室內的某處 – 2013-02-13 14:10:21

回答

-1

請嘗試以下格式,如果它是SQL Server用戶模式,

ConStr = "Server=JAMES-PC\SQLEXPRESS;Database=projectDB;User Id=james; 
Password=password;" 

,如果你想使用Windows連接,

,那麼你必須提供Trusted Connection = true

2

您的SQL SERVER配置爲Windows Only連接並且您當前的wi ndows用戶不相關爲可信。嘗試配置您的SQL SEREVR以接受Mixed Mode連接。

+0

服務器已被更改爲支持但仍然是相同的錯誤 – 2013-02-13 14:11:28

+0

@jamesmews您是否在更改後重新啓動SQL SERVER服務? – 2013-02-13 14:13:41

+0

是的,但它沒有效果,你知道IntegratedSecurity? – 2013-02-13 14:23:31

0

試試這個,我不知道,但希望它會與工作

<connectionStrings> 
<add name ="conStr" connectionString ="Initial Catalog = projectDB; 
Data Source =JAMES-PC\SQLEXPRESS; User Id=james;Password=password;"/> 
</connectionStrings> 
+0

仍然是一樣的錯誤 – 2013-02-13 14:15:36

0

嘗試映射projectDB用戶:詹姆斯。打開SQL Server Management Studio,選擇安全 - 登錄,雙擊用戶:james,選擇頁面:用戶映射,檢查projectDB。

相關問題