我正在尝试将VB.net连接到SQL服务器以获取一些信息,我从Microsoft Technet获得了连接脚本但是它为用户提供了登录失败:domain \ user。虽然该帐户具有dbowner权限,但也是一个服务帐户。我在同一台机器上成功创建了powershell和Sql数据库之间的连接。
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
'Create ADO.NET objects.
Private myConn As SqlConnection
Private myCmd As SqlCommand
Private myReader As SqlDataReader
Private results As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Create a Connection object.
myConn = New SqlConnection("Initial Catalog=VMdbInventory;" & _
"Data Source=MONITORING\SQLEXPRESS;Integrated Security=SSPI;")
'Create a Command object.
myCmd = myConn.CreateCommand
myCmd.CommandText = "SELECT * from vmonhost"
'Open the connection.
myConn.Open()
myReader = myCmd.ExecuteReader()
'Concatenate the query result into a string.
Do While myReader.Read()
results = results & myReader.GetString(0) & vbTab & _
myReader.GetString(1) & vbLf
Loop
'Display results.
MsgBox(results)
'Close the reader and the database connection.
myReader.Close()
myConn.Close()
End Sub
End Class
任何想法我在这里缺少什么?