在连接数据库时出现下面的问题,一直不能解决啊:
用户 '' 登录失败。该用户与可信 SQL Server 连接无关联。代码是:Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim conn As New SqlConnection("server=localhost;database=工作数据库;integrated security=SSPI")
        Dim cmd As New SqlCommand("select * from 新闻表 where id=" & Request.QueryString("id"), conn)
        conn.Open()
        Dim dr As SqlDataReader = cmd.ExecuteReader()
        dr.Read()
        Me.message.Text = dr.Item("newsbt")
End Sub

解决方案 »

  1.   

    数据库是MSSql还是SelExpress ,lz要搞清楚
      

  2.   

      // "uid=sa":连接数据库的用户名为sa.
                // "password=":连接数据库的验证密码为空.他的别名为"pwd",所以我们可以写为"pwd=".
                // "initial catalog=Northwind":使用的数据源为"Northwind"这个数据库.他的别名为"Database",本句可以写成"Database=Northwind".
                // "Server=YourSQLServer":使用名为"YourSQLServer"的服务器.他的别名为"Data Source","Address","Addr".
                // " Connect Timeout=30":连接超时时间为30秒.(根据情况添加)
                // PS:
                //  1.你的SQL Server必须已经设置了需要用户名和密码来登录,否则不能用这样的方式来登录.如果你的SQL Server设置为Windows登录,那么在这里就不需要使用"uid"和"password"这样的方式来登录,而需要使用"Trusted_Connection=SSPI"来进行登录.
                //  2. 如果使用的是本地数据库且定义了实例名,则可以写为"Server=(local)\实例名";如果是远程服务器,则将"(local)"替换为远程服务器的名称或IP地址.
                string strConnection = "Trusted_Connection=SSPI;";
                strConnection += "database=NTF_Navision_enlistment60;Server=CAIXIATA-6BE823;";
                strConnection += "Connect Timeout=30";
      

  3.   

    http://www.connectionstrings.com/
      

  4.   

    数据库中用户不存在或密码不正确,服务器是否开启 
    在安全性里看看用户 
    打开SQL Server Management Studio Express, 
    右键点击服务器,选择Properties(属性),在弹出窗口中点击Security(安全)切换到安全面板, 
    将server authentication服务器认证从windows authentication mode(windows用户认证模式) 
    修改为Sql Server and Windows Authentication mode(Sql server和windows认证模式),ok。 
    打开security(安全性) -- logins(登录名) ,右键选中sa,选择properties(属性),点击Status(状态)切换到状态面板,将Login(登录)设置为Enabled(启用)。 
      

  5.   

    我用的是windows身份验证啊,上面的写法不对吗?应该怎样改啊?而且是基于vb语言的,怎样改正啊
      

  6.   

    windows身份验证的话不是不用密码和用户名的吗、
      

  7.   

    http://connectionstrings.com/