--------------------------------------------------------------------------------
Please tell me how can I make DSN programatically to a password protected Access DB.
Thanks
Best Regards,
Iqbal
2 1917
Hi there,
Kindly refer to below code segment in-order to check / create DSN connection, hope it helps. Good luck & Take care. -
'in module file
-
Private Const KEY_QUERY_VALUE = &H1
-
Private Const ERROR_SUCCESS = 0&
-
Private Const REG_SZ = 1
-
Private Const HKEY_LOCAL_MACHINE = &H80000002
-
Private Const REG_DWORD = 4
-
-
-
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
-
-
-
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long ' Note that If you declare the lpData parameter as String, you must pass it By Value.
-
-
-
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
-
-
-
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
-
-
-
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
-
-
-
Private Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
-
-
-
Public Function isSZKeyExist(szKeyPath As String, _
-
szKeyName As String, _
-
ByRef szKeyValue As String) As Boolean
-
Dim bRes As Boolean
-
Dim lRes As Long
-
Dim hKey As Long
-
lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
-
szKeyPath, _
-
0&, _
-
KEY_QUERY_VALUE, _
-
hKey)
-
-
-
If lRes <> ERROR_SUCCESS Then
-
isSZKeyExist = False
-
Exit Function
-
End If
-
lRes = RegQueryValueEx(hKey, _
-
szKeyName, _
-
0&, _
-
REG_SZ, _
-
ByVal szKeyValue, _
-
Len(szKeyValue))
-
RegCloseKey (hKey)
-
-
-
If lRes <> ERROR_SUCCESS Then
-
isSZKeyExist = False
-
Exit Function
-
End If
-
isSZKeyExist = True
-
End Function
-
-
-
Public Function checkAccessDriver(ByRef szDriverName As String) As Boolean
-
Dim szKeyPath As String
-
Dim szKeyName As String
-
Dim szKeyValue As String
-
Dim bRes As Boolean
-
-
-
bRes = False
-
-
szKeyPath = "SOFTWARE\ODBC\ODBCINST.INI\Microsoft Access Driver (*.mdb)"
-
szKeyName = "Driver"
-
szKeyValue = String(255, Chr(32))
-
-
-
-
If isSZKeyExist(szKeyPath, szKeyName, szKeyValue) Then
-
szDriverName = szKeyValue
-
bRes = True
-
Else
-
bRes = False
-
End If
-
-
checkAccessDriver = bRes
-
End Function
-
-
-
Public Function checkWantedAccessDSN(szWantedDSN As String) As Boolean
-
Dim szKeyPath As String
-
Dim szKeyName As String
-
Dim szKeyValue As String
-
Dim bRes As Boolean
-
-
szKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
-
szKeyName = szWantedDSN
-
szKeyValue = String(255, Chr(32))
-
-
-
-
If isSZKeyExist(szKeyPath, szKeyName, szKeyValue) Then
-
bRes = True
-
Else
-
bRes = False
-
End If
-
-
checkWantedAccessDSN = bRes
-
-
End Function
-
-
-
Public Function createAccessDSN(szDriverName As String, _
-
szWantedDSN As String) As Boolean
-
-
Dim hKey As Long
-
Dim szKeyPath As String
-
Dim szKeyName As String
-
Dim szKeyValue As String
-
Dim lKeyValue As Long
-
Dim lRes As Long
-
Dim lSize As Long
-
Dim szEmpty As String
-
-
szEmpty = Chr(0)
-
-
-
lSize = 4
-
lRes = RegCreateKey(HKEY_LOCAL_MACHINE, _
-
"SOFTWARE\ODBC\ODBC.INI\" & _
-
szWantedDSN, _
-
hKey)
-
-
-
-
If lRes <> ERROR_SUCCESS Then
-
createAccessDSN = False
-
Exit Function
-
End If
-
-
lRes = RegSetValueExString(hKey, "UID", 0&, REG_SZ, _
-
szEmpty, Len(szEmpty))
-
-
szKeyValue = App.Path & "\DB\ssmdb.mdb"
-
lRes = RegSetValueExString(hKey, "DBQ", 0&, REG_SZ, _
-
szKeyValue, Len(szKeyValue))
-
szKeyValue = szDriverName
-
lRes = RegSetValueExString(hKey, "Driver", 0&, REG_SZ, _
-
szKeyValue, Len(szKeyValue))
-
szKeyValue = "MS Access;"
-
lRes = RegSetValueExString(hKey, "FIL", 0&, REG_SZ, _
-
szKeyValue, Len(szKeyValue))
-
lKeyValue = 25
-
lRes = RegSetValueExLong(hKey, "DriverId", 0&, REG_DWORD, _
-
lKeyValue, 4)
-
-
lKeyValue = 0
-
lRes = RegSetValueExLong(hKey, "SafeTransactions", 0&, REG_DWORD, _
-
lKeyValue, 4)
-
-
lRes = RegCloseKey(hKey)
-
szKeyPath = "SOFTWARE\ODBC\ODBC.INI\" & szWantedDSN & "\Engines\Jet"
-
-
lRes = RegCreateKey(HKEY_LOCAL_MACHINE, _
-
szKeyPath, _
-
hKey)
-
-
-
-
If lRes <> ERROR_SUCCESS Then
-
createAccessDSN = False
-
Exit Function
-
End If
-
lRes = RegSetValueExString(hKey, "ImplicitCommitSync", 0&, REG_SZ, _
-
szEmpty, Len(szEmpty))
-
szKeyValue = "Yes"
-
lRes = RegSetValueExString(hKey, "UserCommitSync", 0&, REG_SZ, _
-
szKeyValue, Len(szKeyValue))
-
lKeyValue = 2048
-
lRes = RegSetValueExLong(hKey, "MaxBufferSize", 0&, REG_DWORD, _
-
lKeyValue, 4)
-
-
lKeyValue = 5
-
lRes = RegSetValueExLong(hKey, "PageTimeout", 0&, REG_DWORD, _
-
lKeyValue, 4)
-
-
lKeyValue = 3
-
lRes = RegSetValueExLong(hKey, "Threads", 0&, REG_DWORD, _
-
lKeyValue, 4)
-
-
lRes = RegCloseKey(hKey)
-
lRes = RegCreateKey(HKEY_LOCAL_MACHINE, _
-
"SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", _
-
hKey)
-
-
-
-
If lRes <> ERROR_SUCCESS Then
-
createAccessDSN = False
-
Exit Function
-
End If
-
-
szKeyValue = "Microsoft Access Driver (*.mdb)"
-
lRes = RegSetValueExString(hKey, szWantedDSN, 0&, REG_SZ, _
-
szKeyValue, Len(szKeyValue))
-
-
lRes = RegCloseKey(hKey)
-
createAccessDSN = True
-
End Function
-
'anywhere in application
-
-
Dim szDriverName As String
-
Dim szWantedDSN As String
-
-
szDriverName = String(255, Chr(32))
-
szWantedDSN = "MyAccess_ODBC"
-
'is access drivers installed?
-
-
-
If Not checkAccessDriver(szDriverName) Then
-
MsgBox "You must Install Access ODBC Drivers before use this program.", vbOK + vbCritical
-
End If
-
-
'is our dsn exist?
-
-
-
If Not (checkWantedAccessDSN(szWantedDSN)) Then
-
-
-
If szDriverName = "" Then
-
MsgBox "Can't find access ODBC driver.", vbOK + vbCritical
-
Else
-
-
-
If Not createAccessDSN(szDriverName, szWantedDSN) Then
-
MsgBox "Can't create database ODBC.", vbOK + vbCritical
-
End If
-
End If
-
End If
-
--------------------------------------------------------------------------------
Please tell me how can I make DSN programatically to a password protected Access DB.
Thanks
Best Regards,
Iqbal
Hi there,
Kindly refer to below code segment in-order to check / create DSN connection, hope it helps. Good luck & Take care.
Hi, welcome back.
Mary
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kelly Bowles |
last post by:
I have made a purchase requistion which I have been asked to put password
protected copy of requestors signature.
I am thinking that each signature will have to be scanned as a picture and
linked...
|
by: MissiMaths |
last post by:
I have used outputTo to export a copy of a table out of access into
excel. I was wondering if there is anyway to set a password on this
within the code so that it is read only in .xls format?
I...
|
by: Kevin Vogler |
last post by:
I need to read the value of a hidden field on a remote HTML page and then
use that value in a form submit on my local page.
How can I read the hidden field programatically?
Thanks in advance....
|
by: kthiagar |
last post by:
Hi
I am trying to connect to a password protected access file from VB.NET.
I have no problem in connecting to Access, if I remove the password.
This is what I am doing:
In the server explorer,...
|
by: Miro |
last post by:
Why Password protect an MDB when someone can google and get a hack?
Wondering if anyone else has thought of this and just said "oh well"...
I plan to password protect an MDB where I have some...
|
by: Noel S Pamfree |
last post by:
Problem 1
=======
I need to create a page for a friend who operates a school website. She
needs to set up a page so that only the Governors can access it. I thought
I'd try to use JavaScript to...
|
by: -xx- |
last post by:
Hi,
I am new to c# and just trying out c# with ms access. First problem i
encountered is how do i open up ms access that has password.
Here is my current codes which working fine if there is...
|
by: gngui |
last post by:
Hi,
Please Please Please anyone out there, if you have a solution, i will highly appreciate as i have searched the internet for 5 days now with no hope.
1st, the versions i am using are Ms Access...
|
by: n8kindt |
last post by:
i'm trying to create a secure scenario where no one will be able to know our encrypted database passcode. BUT if they login to a form in another database successfully, it will open the encrypted...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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...
| |