【问题标题】:Error connecting to SQL server through string, not recognising user name or password通过字符串连接 SQL Server 时出错,无法识别用户名或密码
【发布时间】:2013-01-29 01:59:05
【问题描述】:

我遇到的问题是从 ASP.NET 应用程序连接到我的 sql server (2005) 上的帐户。

我尝试使用默认的 sa 登录名,并且我已经创建的用户也将 sql management studio 的设置设置为混合属性,我在 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();

我收到的错误信息是:

用户“james”登录失败。该用户未与受信任的 SQL Server 连接关联。

任何帮助表示赞赏 詹姆斯

【问题讨论】:

  • 也许您需要 IntegratedSecurity=SSPI ?
  • 使用sql账户时设置IntegratedSecurity=false
  • 这段代码在 webconfig 中的什么位置?或管理工作室中的某个地方
  • 好的,谢谢您的回复

标签: c# asp.net sql-server dataadapter


【解决方案1】:

您为Windows Only 连接配置的 SQL SERVER 和您当前的 Windows 用户未关联为受信任。尝试将您的 SQL SEREVR 配置为接受 Mixed Mode 连接。

【讨论】:

  • 服务器已更改为支持两者但仍然相同的错误
  • @jamesmews 更改后是否重启 SQL SERVER 服务?
  • 是的,但是没有效果,你知道IntegratedSecurity吗?
  • 我已经开始工作了,感谢您最后的回复,Integrated Security=SSPI。
  • @jamesmews Integrated Security=SSPI 允许您使用 windows 帐户登录,如果您尝试使用 SQL Server 登录,则不需要您。
【解决方案2】:

试试这个,我不确定,但希望它会起作用-

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

【讨论】:

    【解决方案3】:

    尝试将 projectDB 映射到 user:james。打开SQL Server Management Studio,选择Security - Logins,双击用户:james,选择页面:User Mapping,查看projectDB。

    【讨论】:

      【解决方案4】:

      如果是Sql Server用户模式,请尝试以下格式,

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

      如果您尝试使用 Windows 进行连接,

      那么你必须提供Trusted Connection = true

      【讨论】:

        猜你喜欢
        • 2015-11-24
        • 2021-10-31
        • 2020-07-15
        • 1970-01-01
        • 2013-06-17
        • 2021-11-06
        • 2010-12-30
        • 2021-08-02
        • 2023-02-24
        相关资源
        最近更新 更多