Nasty connection String error / encoding.ascii.getstring error

J

james

I am creating an connection string at runtime using decryption (crypto
libraries).

i have a very unpridictable error while assinging the generated
connection string to the connection property.

my code is something like this ...

Public Function DbconnStr(ByVal UID As String, ByVal Pwd As String, _
ByVal ServerName As String,
ByVal DbName As String) As StringBuilder

Dim str as stringbuilder
Dim UIDinfo As String =
Convert.ToBase64String(DecryptData.Decrypt(Encoding.ASCII.GetBytes(UID)))
Dim PWDinfo As String =
Convert.ToBase64String(DecryptData.Decrypt(Encoding.ASCII.GetBytes(Pwd)))

Str.Append("Server=")
Str.Append(ServerName)
Str.Append(";Database=")
Str.Append(DbName)
Str.Append(";User ID=")
Str.Append(UIDinfo)
Str.Append(";password=")
Str.Append(PWDinfo)
Str.Append(";Trusted_Connection=False")

Catch ex As Exception
Throw New Exception("In WASC " & ex.Message)
End Try
Return Str
End Function


the generated string ... something like
--"Server=GVA21943\SQLSERVER;Database=Northwind;User

ID=WASCuser;password=welcome;Trusted_Connection=False"

the error is ---Format of the initialization string does not conform
to specification starting at index 61. -- which is always the end of

user ID.

If i hard code the same value i am thru the connection.
Also i noticed an additional char when i find the length of the string
generated for UIDinfo and PWDinfo.
so when i delete the last character generated ... again the connection
is thru at runtime.
But without deleting when i print the connectstring ... i don't find
that character ...its invisible....

pls help me to know y that invisible character (at the end of the
generated string for UIDinfo and PWDinfo) giving me this nasty error.

thanks.
 
J

Jay B. Harlow [MVP - Outlook]

James,
What is DecryptData.Decrypt?
pls help me to know y that invisible character (at the end of the
generated string for UIDinfo and PWDinfo) giving me this nasty error.

Are you comfortable that DecryptData.Decrypt or Convert.ToBase64String are
not including a trailing character on the end of the string that is being
returned?

Such as a trailing null char (ChrW(0)) or something?

Or even your input string itself.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top