VB.NET连接SQL2008数据库的问题
一个FROM上建立Button1,主要实现其测试数据库连接状态的功能。为何一直总是提示未连接,哪里出错了,这下面的是书上的源码。ImportsSystemImportsS...
一个FROM上建立Button1,主要实现其测试数据库连接状态的功能。为何一直总是提示未连接,哪里出错了,这下面的是书上的源码。
Imports System
Imports System.Data.SqlClient
Public Class Form1
Dim Conn As SqlClient.SqlConnection '声明Conn da ds 为数据库各类型对象
Dim da As SqlDataAdapter
Dim ds As DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Conn = New SqlConnection()
Conn.ConnectionString = "Data Source=(local);Initial Catalog=master;Intergrated Security=false;User ID=sa;Password=yhyhyh"
Conn.Open()
MessageBox.Show(Conn.State.ToString())
Conn.Close()
Catch
MessageBox.Show("未连接")
End Try
End Sub
End Class 展开
Imports System
Imports System.Data.SqlClient
Public Class Form1
Dim Conn As SqlClient.SqlConnection '声明Conn da ds 为数据库各类型对象
Dim da As SqlDataAdapter
Dim ds As DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Conn = New SqlConnection()
Conn.ConnectionString = "Data Source=(local);Initial Catalog=master;Intergrated Security=false;User ID=sa;Password=yhyhyh"
Conn.Open()
MessageBox.Show(Conn.State.ToString())
Conn.Close()
Catch
MessageBox.Show("未连接")
End Try
End Sub
End Class 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询