Try to use Password
keyword instead of pwd
provider=sqloledb;database=data_base_name;server=server_name;uid=sa;Password="test;password"
문제
I have to support an older component which is written in VB6. The componenent has methods to access the database via ADO Recordset.
Now I run into an error while I found out that someone uses a semicolon in a password. As semicolon is a reserved character it needs to be escaped.
Found this resource: http://www.connectionstrings.com/formating-rules-for-connection-strings/ and http://msdn.microsoft.com/en-us/library/windows/desktop/ms722656(v=vs.85).aspx
So I tried add this code:
Private Function MaskString(ByVal p_sVal)
Dim l_sString As String
Dim l_sQuote As String
l_sQuote = """"
l_sString = p_sVal
If InStr(1, l_sString, """") > 0 Then l_sQuote = "'"
If InStr(1, l_sString, ";") > 0 Then l_sString = l_sQuote & l_sString & l_sQuote
MaskString = l_sString
End Function
So I call this function for each value and the final connection string then is like:
provider=sqloledb;database=data_base_name;server=server_name;uid=sa;pwd="test;password"
Used like:
AdoConnection.ConnectionTimeout = lConnectionTimeout
AdoConnection.ConnectionString = strConnectionString
AdoConnection.Open
However this seems to be correct now, but VB6 Ado give me the following error now:
Method OpenDB: -2147467259 - Ungültiges Attribut für die Verbindungszeichenfolge - Microsoft OLE DB Provider for SQL Server
(Probably english is like - Invalid attribute for the connection string - )
So old VB6 doesn't support this? Or how do I escape those reserved chars then?
해결책
Try to use Password
keyword instead of pwd
provider=sqloledb;database=data_base_name;server=server_name;uid=sa;Password="test;password"
다른 팁
Maybe if you pass the semicolon using chr(59) it might help ? Also lookout for the double quotes.
Connection string = "provider=sqloledb" & chr(59) & "database=data_base_name" & chr(59) & "server=server_name" & chr(59) & "uid=sa" & chr(59) & "pwd="""test" & chr(59) & "password"""