SqlConnection sqlcon =new SqlConnection
("DataSource=.\\sqlexpress;Initial Catalog=db;Integrated Security=SSPI");
SqlDataAdapter sqlda = new SqlDataAdapter("select * from tb",sqlcon );
SqlCommand sqlcmd = new SqlCommand("select * from tb",sqlcon );
DataSet ds = new DataSet();
sqlda.Fill(ds,"pp");
this.dataGridView1.DataSource=ds.Tables[0];每次运行后都是出现这个错误!!!请大家帮帮忙!!!我刚接触vs2005!!!谢谢了!!!
Cannot open database "db" requested by the login. The login failed.
Login failed for user 'DEV-830966B997A\wb'.

解决方案 »

  1.   

    SQL 2005还没有用过,看看这里,有SQL2005的各种连接方式
    http://www.connectionstrings.com/?carrier=sqlserver2005
      

  2.   

    string connectionString = "server=机器\\SQLEXPRESS;database=数据库名称;User ID=sa;password=密码";
      

  3.   

    现在关键的是我装的是vs2005自带的sql2005,没有uid和pwd.
      

  4.   

    首先你测试了你的连接字符串是正确的吗?如果是正确,你要打开你的连接呀,sqlcon.open(),然后再调用!
      

  5.   

    我只要是写上sqlcon.open()就错!!!
      

  6.   

    你的连接字符串可能有问题DataSource=.\\sqlexpress;Initial Catalog=db;Integrated Security=SSPI另外,检查一下你的sql的配置是否正确。
      

  7.   

    sql2005是怎么配置我不知道啊!他不像是SQL2000!
      

  8.   

    有没有人连上过vs2005&sql2005的,请指教一下!
      

  9.   

    我就是那么直接联的阿,和2000一样,我觉得也就是05把企业管理器和查询分析器和并在一起了,估计你的语句有问题,按照上面说的string connectionString = "server=机器\\SQLEXPRESS;database=数据库名称;User ID=sa;password=密码";这么写不行吗??
      

  10.   

    我这样写了,出错!我一开始也以为和SQL2000一样,但是实际上却是出错了!我也不知道这是为什么??
      

  11.   

    DataSource=.\\sqlexpress;Initial Catalog=db;Integrated Security=SSPI
    你可以试2003连接方式:server=.;uid=sa;pwd=;database=;
    然后sqlcon.open()调用就可以用这个对象了
      

  12.   

    我也这样连过,可能是我的版本不行吧!我装的是c# Expression Edition