hong34210
2015-04-18 05:26
采纳率: 97%
浏览 1.5k

连接不了数据库,其他信息

“System.Data.SqlClient.SqlException”类型的未经处理的异常在 System.Data.dll 中发生

其他信息: 用户 'MicrosoftAccount\hong34210@hotmail.com' 登录失败。

  //创建连接对象
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["partialConnectString"].ToString();
            //建立命令对象
            SqlCommand cmd = new SqlCommand("select l_number,l_type,workHours,exaWorkHours,l_unitPrice,unitPriceTerms,exaUnitPriceTerms from LCA where number=0", conn);
            //创建适配器对象
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = cmd;
            //创建数据集
            DataSet deptDataSet = new DataSet();
            //填充数据集
            adapter.Fill(deptDataSet, "lca");
            //绑定数据
            DataView dv = new DataView(deptDataSet.Tables["lca"]);

            this.dgvLCA.DataSource = dv;
            this.dgvLCA.Columns[0].HeaderText = "序号";
            this.dgvLCA.Columns[1].HeaderText = "加工类型";
            this.dgvLCA.Columns[2].HeaderText = "工时";
            this.dgvLCA.Columns[3].HeaderText = "审核工时";
            this.dgvLCA.Columns[4].HeaderText = "单价(元)";
            this.dgvLCA.Columns[5].HeaderText = "单价项";
            this.dgvLCA.Columns[6].HeaderText = "审核单价项";

app。config里

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="partialConnectString"
        connectionString="Data Source=.;Initial Catalog=NAVECODB; User ID=sa; Password=123456;Integrated Security=True"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • threenewbee 2015-04-18 05:27
    已采纳

    Integrated Security=false
    你这个是用sa去连的。

    打赏 评论

相关推荐 更多相似问题