我在使用ADODB.Recordset时遇到一些问题。我调用一个存储过程,该过程返回密码并从数据库登录。一旦执行了usp,密码和登录名都将被加载到记录集中。如果在将密码设置为字符串之前放置了任何代码行,则密码值将恢复为Null。这与登录名无关,仅与密码有关。我有什么想法可以解决此问题?
Dim objConn As ADODB.Connection
Dim rstResult As ADODB.recordset
Dim objCmd As New ADODB.Command
Dim Param As cSQLParam
Dim ParamValue As Variant
Dim lngNumRec As Long
Set objConn = New ADODB.Connection
objConn.Open "DSN=" & GetProfileString(gRootFolder & "InputFolder\" & "ODBC.bds", "General", "DSN")
Set objCmd = New ADODB.Command
With objCmd
.ActiveConnection = objConn
.CommandText = "[dbo].[usp_Credentials_GetUserCredentials]"
.CommandType = adCmdStoredProc
.CommandTimeout = 0
For Each Param In Params
.Parameters.Append .CreateParameter(Param.Name, Param.DataType, Param.Direction, Param.Size, IIf(Param.Value = "", Null, Param.Value))
Next
End With
Set rstResult = objCmd.Execute
'any time I add code here the password shows up as Null, If no code is here the
'correct password is displayed. Could this have to do with the password being
'encrypted with a Salt on the server?
'Capture the password
gDataRecord.Password = rstResult("Password")
'Capture the Login
gDataRecord.Login = rstResult("LoginName")
rstResult.Close
objConn.Close
答案 0 :(得分:0)
我发现了问题。当我将密码更改为(255)时,密码被定义为NVARCHAR(MAX)。记录集保存变量。谢谢所有看过这个的人。