/* */

Wednesday, January 9, 2013

[belajar-access] Re: DSN dengan VBA di Windows 7

 

saya coba kok belum berhasil ya bang Sofyan,.... Kalau untuk cek apakah Nama DSN tertentu sudah ada apa belum gimana ya..
Terimakasih sebelumnya..

--- In belajar-access@yahoogroups.com, Sofyan Efendi wrote:
>
> Kalau Win7 64 bit sepertinya saya dulu pernah coba tapi gagal, karena ODBC nya penempatannya berbeda di registrynya. Lokasi di:
> HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\Nama dari SYSTEM DSN di PC nya
> Mungkin bisa dicoba langsung set ke registry, misal:
> Option Compare Database
> Option Explicit
> Option Base 1
>
> Private Const REG_SZ = 1 'Constant for a string variable type.
> Private Const HKEY_LOCAL_MACHINE = &H80000002
>
> 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 RegSetValueEx Lib "advapi32.dll" Alias _
> "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
> ByVal reserved As Long, ByVal dwType As Long, lpData As Any, ByVal _
> cbData As Long) As Long
>
> Private Declare Function RegCloseKey Lib "advapi32.dll" _
> (ByVal hKey As Long) As Long
>
> Public Function Add_DSN_Win7_System_DSNs()
>
> 'Open Þ Load Þ Resize Þ Activate Þ Current
>
> Dim DataSourceName As String
> Dim DatabaseName As String
> Dim Description As String
> Dim Driver As String
> Dim DriverName As String
> Dim LastUser As String
> Dim Regional As String
> Dim Server As String
> Dim AddSetup As String
>
> Dim lResult As Long
> Dim hKeyHandle As Long
>
> DriverName = "SQL Server"
>
> 'Specify the DSN parameters.
>
> DataSourceName = "TestDSN1"
> DatabaseName = "Adventureworks"
> Description = "Adventureworks Database ODBC Call"
> Driver = "C:\Windows\system32\SQLSRV32.dll"
> LastUser = "sa"
> Server = "(local)"
> AddSetup = "No"
>
> 'Create the new DSN key.
>
> lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Wow6432Node\ODBC\ODBC.INI" & _
> DataSourceName, hKeyHandle)
>
> 'Set the values of the new DSN key.
>
> lResult = RegSetValueEx(hKeyHandle, "QuotedId", 0&, REG_SZ, _
> ByVal AddSetup, Len(AddSetup))
> lResult = RegSetValueEx(hKeyHandle, "AnsiNPW", 0&, REG_SZ, _
> ByVal AddSetup, Len(AddSetup))
> lResult = RegSetValueEx(hKeyHandle, "AutoTranslate", 0&, REG_SZ, _
> ByVal AddSetup, Len(AddSetup))
> lResult = RegSetValueEx(hKeyHandle, "Database", 0&, REG_SZ, _
> ByVal DatabaseName, Len(DatabaseName))
> lResult = RegSetValueEx(hKeyHandle, "Description", 0&, REG_SZ, _
> ByVal Description, Len(Description))
> lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, _
> ByVal Driver, Len(Driver))
> lResult = RegSetValueEx(hKeyHandle, "LastUser", 0&, REG_SZ, _
> ByVal LastUser, Len(LastUser))
> lResult = RegSetValueEx(hKeyHandle, "Server", 0&, REG_SZ, _
> ByVal Server, Len(Server))
>
> 'Close the new DSN key.
>
> lResult = RegCloseKey(hKeyHandle)
>
> 'Open ODBC Data Sources key to list the new DSN in the ODBC Manager.
> 'Specify the new value.
> 'Close the key.
> 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI
> 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\test2sql
> lResult = RegCreateKey(HKEY_LOCAL_MACHINE, _
> "SOFTWARE\Wow6432Node\ODBC\ODBC.INI\ODBC Data Sources", hKeyHandle)
> lResult = RegSetValueEx(hKeyHandle, DataSourceName, 0&, REG_SZ, _
> ByVal DriverName, Len(DriverName))
> lResult = RegCloseKey(hKeyHandle)
>
> End FunctionSumber: http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_26763877.html
>
> Wassalaamu'alaikum Warahmatullahi Wabarakatuh,
> Sofyan Efendi
> ----- Original Message -----
> From: Didik Supriyadi
> To: belajar-access@yahoogroups.com
> Sent: Monday, January 07, 2013 1:04 AM
> Subject: [belajar-access] DSN dengan VBA di Windows 7
>
>
>
>
>
> Gimana ya cara buat DSN dengan VBA di OS windows 7 ? ....
>
> mohon pencerahannya...
>

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)
Recent Activity:
SPAM IS PROHIBITED
.

__,_._,___

No comments:

Post a Comment