如何保护Vb6应用程序和mssql服务器之间的连接?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何保护Vb6应用程序和mssql服务器之间的连接?相关的知识,希望对你有一定的参考价值。
我正在使用一个遗留应用程序,它使用sqloledb提供程序和activex数据对象连接到mssql数据库。现在我需要在sql server中加密应用程序和服务器之间的连接而不使用强制加密选项。
我在sql server实例中安装了自签名证书,并尝试将Encrypt=true
和Trustservercertificate=true
放在连接字符串中。但是连接没有加密。
我尝试使用ODBC提供程序与ADO,并在使用encrypt=true
和trustservercertificate=true
时,我收到一个SSL安全错误,打开连接。
请告诉我如何使用ADO 2.8库建立安全连接。
Private Sub Command1_Click()
Dim sConnectionString As String
Dim strSQLStmt As String
'-- Build the connection string
'sConnectionString = "UID=userid;PWD=password;Initial Catalog=EHSC_SYM_Kings_Development;Server=EHILP-257MIB14;Provider=MSOLEDBSQL;Encrypt=YES;trustServerCertificate=YES"
'sConnectionString = "Provider=sqloledb;Data Source=192.168.27.91MIB14;Initial Catalog=EHSC_SYM_Kings_Development;User Id=userid;Password=password;Encrypt=YES;trustServerCertificate=YES"
'sConnectionString = "driver={SQL Server};server=192.168.27.91MIB14;user id=userid;password=password;Initial Catalog=EHSC_SYM_Kings_Development;Encrypt=Yes;trustServerCertificate=True"
sConnectionString = "Provider=SQLNCLI11;Server=192.168.27.91MIB14;Database=EHSC_SYM_Kings_Development;Uid=userid;Pwd=password;Encrypt=yes;trustServerCertificate=True"
strSQLStmt = "select * from dbo.patient where pat_pid = '1001'"
'DB WORK
Dim db As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim result As String
db.ConnectionString = sConnectionString
db.Open 'open connection
With cmd
.ActiveConnection = db
.CommandText = strSQLStmt
.CommandType = adCmdText
End With
With rs
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open cmd
End With
If rs.EOF = False Then
rs.MoveFirst
Let result = rs.Fields(0)
End If
'close conns
rs.Close
db.Close
Set db = Nothing
Set cmd = Nothing
Set rs = Nothing
End Sub
答案
谢谢大家的建议,我终于通过将驱动程序更改为sqlserver本机客户端11(ODBC)来设法使连接安全。看起来sqloledb不支持tls。将驱动程序更改为ODBC似乎不会改变行为。其余的代码工作正常,没有任何更改
sConnectionString = "Driver={SQL Server Native Client 11.0};Server=192.168.27.91MIB14;Database=EHSC_SYM_Kings_Development;user id=Fymphony;password=FEzp[HnR;Encrypt=yes;TrustServerCertificate=yes"
以上是关于如何保护Vb6应用程序和mssql服务器之间的连接?的主要内容,如果未能解决你的问题,请参考以下文章