马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?站点注册
×
我下面的这段测试数据库连接的代码,方法一不管在哪里都没有问题,方法二和方法三在我的开发环境没有问题(装有vs2005和你破解的dw2.0)通过vs2005发布向导发布到其他干净机器上(装有数据库,没有VS2005,没有dw2.0)运行程序,方法一不会报错,但是方法二和方法三都在红色代码的地方报错,不知道什么原因?
Imports Sybase.DataWindow Imports System.Data.SqlClient Public Class Form1 方法一 Private Sub Button1_Click(ByVal sender As System.Object, ByVal ex As System.EventArgs) Handles Button1.Click Try Dim theConnection As New System.Data.SqlClient.SqlConnection("Data Source=localhost\SQLEXPRESS;Initial Catalog=Print;Integrated Security=SSPI;") Dim gSQLCA As New Sybase.DataWindow.AdoTransaction(theConnection, "") theConnection.Open() MsgBox("SqlClient.SqlConnection.open成功")
Catch e As NullReferenceException MsgBox("空指针异常: " + vbCrLf + vbCrLf + e.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Catch e As TransactionException MsgBox("事务错,连接数据库出错: " + vbCrLf + vbCrLf + e.SqlErrorText + vbCrLf + vbCrLf + e.SqlDbCode, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Catch e As InvalidOperationException MsgBox("非法操作,连接数据库出错: " + vbCrLf + vbCrLf + e.Message + vbCrLf + vbCrLf + e.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Catch e As Exception MsgBox("异常操作,连接数据库出错: " + vbCrLf + vbCrLf + e.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Finally End Try End Sub 方法二 Private Sub Button2_Click(ByVal sender As System.Object, ByVal ex As System.EventArgs) Handles Button2.Click Try Dim theConnection As New System.Data.SqlClient.SqlConnection("Data Source=localhost\SQLEXPRESS;Initial Catalog=Print;Integrated Security=SSPI;") Dim gSQLCA As New Sybase.DataWindow.AdoTransaction(theConnection, "") Dim SQLCA As New Sybase.DataWindow.AdoTransaction(theConnection, "") theConnection.Open() MsgBox("SqlClient.SqlConnection.open成功") SQLCA.BindConnection() MsgBox("SQLCA.BindConnection()成功") Catch e As NullReferenceException MsgBox("空指针异常: " + vbCrLf + vbCrLf + e.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Catch e As TransactionException MsgBox("事务错,连接数据库出错: " + vbCrLf + vbCrLf + e.SqlErrorText + vbCrLf + vbCrLf + e.SqlDbCode, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Catch e As InvalidOperationException MsgBox("非法操作,连接数据库出错: " + vbCrLf + vbCrLf + e.Message + vbCrLf + vbCrLf + e.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Catch e As Exception MsgBox("异常操作,连接数据库出错: " + vbCrLf + vbCrLf + e.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Finally End Try End Sub 方法二 Private Sub Button3_Click(ByVal sender As System.Object, ByVal ex As System.EventArgs) Handles Button3.Click Try Dim SQLCA As New Sybase.DataWindow.Transaction SQLCA.Dbms = Sybase.DataWindow.DbmsType.OleDb SQLCA.AutoCommit = True SQLCA.DbParameter = "PROVIDER='SQLOLEDB',DATASOURCE='(local)\SQLEXPRESS',PROVIDERSTRING='database=Print',DelimitIdentifier='Yes',INTEGRATEDSECURITY='SSPI'" SQLCA.Connect() MsgBox(" SQLCA.Connect()成功") Catch e As NullReferenceException MsgBox("空指针异常: " + vbCrLf + vbCrLf + e.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Catch e As TransactionException MsgBox("事务错,连接数据库出错: " + vbCrLf + vbCrLf + e.SqlErrorText + vbCrLf + vbCrLf + e.SqlDbCode, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Catch e As InvalidOperationException MsgBox("非法操作,连接数据库出错: " + vbCrLf + vbCrLf + e.Message + vbCrLf + vbCrLf + e.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Catch e As Exception MsgBox("异常操作,连接数据库出错: " + vbCrLf + vbCrLf + e.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) Finally End Try End Sub End Class
|