我打算检查我的数据库是否连接到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
答案 0 :(得分:1)
试试这个
sqlconn.ConnectionString = "Data Source=(local);Initial Catalog=OJT;Integrated Security=True"
答案 1 :(得分:1)
试试这个:
"Data Source=(local);Initial Catalog=OJT;Persist Security Info=True;User ID=(Your User ID);Password=(Your Password)"
希望它能解决你的问题。美好的一天!