0

我打算检查我的数据库是否连接到我在 vb.net 中的项目,但似乎我的代码或我的 SQL 服务器有问题。它总是向我显示一条消息“用户 'id/id2' 登录失败”。

这是我的代码:

Imports System.Data.SqlClient
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim sqlconn As New SqlConnection
    sqlconn.ConnectionString = "server = (local);Database=OJT;integrated security=true"
    Try
        sqlconn.Open()
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Connection to Sql Server Failed!", MessageBoxButtons.OK)
    End Try
    Me.Text = "You are successfully connected to Sql Server"
End Sub
End Class
4

2 回答 2

1

试试这个

sqlconn.ConnectionString = "Data Source=(local);Initial Catalog=OJT;Integrated Security=True"
于 2013-01-25T08:18:14.923 回答
1

试试这个:

"Data Source=(local);Initial Catalog=OJT;Persist Security Info=True;User ID=(Your User ID);Password=(Your Password)"

希望它能解决你的问题。再会!

于 2013-04-02T03:06:32.960 回答