473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DSN-less ODBC connection doesn't remember PW??

If I connect via MS Access's File|Get External Data|Link Tables and
set RememberPassword=True, the resulting link's .Connect contains UID=
and PWD=
and those values persist even after tha app is closed and reopened.
OTOH if I do something like...

Set myTD = CurrentDB.TableDefs("tblAbc")
With myTD
.Name = curName
.Connect = "ODBC;" & ";UID=" & myUserID & ";PWD=" & myPassword &
";" & (other connectin info)
.SourceTableName = "Whatever"
End With
....the connection gets made and works, but if the app is shut down,
reopened,
and the link is opened; the DB prompts for UserID/PW.

When I look at the links .Connect string, it does not appear to
contain
the UserID or PW that was put into it.
Some kind of Attribute? Property?
Nov 12 '05 #1
1 2134
Not clear on when/how you are invoking your link, like at App Startup?
If so (or something like that) aren't UID and Password parameters you
need to pass to your connect string? If so, then you need to store
these params. If security is an issue here is an encryption routine I
put together (with various snipets from here and there and some of my
own stuff) in VBA (which runs fine in Access). You encrypt the password
and then convert it to a hex string for storage. To run your link
routine reverse the process - you convert the password back to binary
(unhex it) and then decrypt. To decrypt just reverse the arguments for
the encryp function (original args are password, key - to decryp just
call same encrypt function except args are key, encrypted password). At
the bottom is an example how to encrypt/decrypt password:

-----------------------------------------
Function Encrypt(ByVal strInput As String, ByVal strKey As String) As
String
Dim iCount As Long, lngPtr As Long
For iCount = 1 To Len(strInput)
Mid(strInput, iCount, 1) = Chr((Asc(Mid(strInput, iCount, 1))) Xor
(Asc(Mid(strKey, lngPtr + 1, 1))))
lngPtr = ((lngPtr + 1) Mod Len(strKey))
Next iCount
Encrypt = strInput
End Function
-----------------------------------------

-----------------------------------------
Function kSet(n As Integer) As String
Dim ar As Variant
Static i As Integer, str1 As String, str2 As String
ar = Array("a", "b", "c")
If str2 <> "" Then
i = 0
str1 = ""
str2 = ""
End If
If n = 0 Then
str2 = str1
kSet = str2
Else
str1 = str1 & ar(i)
i = i + 1
If i > 2 Then i = 0
n = n - 1
kSet = kSet(n) 'recursive call here - this is mine
End If 'I may have gotten a little carried
End Function 'away here
---------------------------------------------

----------------------------------------------
Function ConvertStringToHex(ByVal sText As String) As String
Dim lCount As Long
Dim sHex As String
Dim sResult As String
Dim lK As Long

sResult = String(2 * Len(sText), vbNull)
lK = 1
For lCount = 1 To Len(sText)
sHex = Hex(Asc(Mid(sText, lCount, 1)))
If Len(sHex) = 1 Then
sHex = "0" & sHex
End If
Mid$(sResult, lK, 2) = sHex
lK = lK + 2
Next

ConvertStringToHex = sResult
End Function
--------------------------------------------

-------------------------------------------
Public Function ConvertStringFromHex(ByVal sText As String) As String
Dim lCount As Long
Dim sChar As String
Dim sResult As String
Dim lLength As Long
Dim nJ As Long

lLength = Len(sText)
sResult = String(lLength / 2, vbNull)
nJ = 1
For lCount = 1 To lLength Step 2
Mid$(sResult, nJ, 1) = Chr(Val("&H" & Mid(sText, lCount, 2)))
nJ = nJ + 1
Next

ConvertStringFromHex = sResult
End Function
-----------------------------------------------

To Encrypt password place this function in a form module

Function EncryptPwrd()
str1 = Encrypt(txtPassword, kSet(Len(txtPassword)))
txtPassword = str1
str1 = ConvertStringToHex(str1) 'convert to hexString here
End Function

The purpose of hexing is so you can use the encrypted password in a sql
string - sql doesn't support binary text. However, DAO will write
binary text so you would not have to hex if you wanted to use DAO for
writing the encrypted password somewhere.

To decryp, I would just place the Encrypt call in the connect string -
inline - arguments are reversed here. But first need to unHex password

strPassword = ConvertStringFromHex(strPassword)
strConnect = "...
PWD=" & (Encrypt(kSet(Len(strPassword)), strPassword)) & ";"

here strPassword contains the deHexed-binary password, and args are
reversed for call to Encrypt.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: McCool | last post by:
How can I get the deployment project to setup a DSN pointing to an Access DB after installation takes place? Also, is there a way to kick off a vbs script after installation takes place through...
3
by: Zlatko Matić | last post by:
Hi! What happens with linked tables if they were linked using File DSN, when I copy the Access file on some other PC without File DSN ? What is the difference between DSN on linked tables and...
4
by: Steve Sweales | last post by:
I'm trying to find some code on how to create a DSN using C# and SQLConfigDataSource. Can anybody help me please, before I tear my hair out!! *** Sent via Devdex http://www.devdex.com ***...
3
by: Charlie | last post by:
Hi: I created a config file to retrieve DSN at runtime from a C# library project (DLL). I name the file same as DLL (libRADIUS.config). Here is the contents of the file... <?xml...
3
by: Niks | last post by:
Hi, I need to connect to SQL server Database using a System DSN. Can anyone tell me how to connect to SQL Server using DSN in ASP.NET (VB.Net). Using a Try Catch block. Does anyone know how to...
4
by: Bill Nguyen | last post by:
I created several CR reports (in r8.5 and r10) using a system DSN named "CrystalUser" with username and login ID and use them in my VB.NET app. In order for my clients to run the report, the...
14
by: kdv09 | last post by:
Hi! I'm looking for some help in fixing my screwup: I've got C++ app which reads MDB database, using MFC CDatabase and CRecordset derived classes. I had it working OK on development PC (Win XP...
5
by: Arpan | last post by:
I created a System DSN named "NETData" for a SQL Server 2005 Express database. Now to make use of this System DSN to access records in the DB table, this is how I framed the ConnectionString: ...
5
by: anaphaxeon | last post by:
I'm wondering if there are any scripting gurus out there that can help with my situation. Here goes... So I've made this .NET application that manages an engineering firm's drawings, this...
4
by: bytesbytes | last post by:
Hi, Im using VB6.0, Crystal report 10 and MSaccess Database. I was using Crystal report 6 and later upgraded to CR10. In VB6 i used DSN like .Connect = "DSN=DBName" & ";UID=admin;PWD=;" Now in...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.