Create System DSN using LotusScript, Working sample

Here’s a script for all of you who want your Notes-clients to be able to create a DSN in order for ODBC-connections to work.

Put the code in a button in your applications and the clients can create it themselves.

Sub Initialize

On Error Goto errhandle



Dim DataSourceName As String

Dim DatabaseName As String

Dim Description As String

Dim DriverPath As String

Dim DriverName As String

Dim LastUser As String

Dim Regional As String

Dim Server As String



Const SystemFolder= 1

Dim WshShell As Variant

Dim fso As Variant

Dim SysFolder As Variant

Dim SysFolderPath As String



Set WshShell = CreateObject("WScript.Shell")

Set fso = CreateObject("Scripting.FileSystemObject")

Set SysFolder = fso.GetSpecialFolder(SystemFolder)

SysFolderPath = SysFolder.Path

'Specify the DSN parameters.

DataSourceName = "Your source name"

DatabaseName = "Your default database name"

Description = "Your Short descripion of DSN"

DriverPath = SysFolderPath & "\sqlsrv32.dll"

Server = "Your IP-adress or servername"

LastUser  = "Your database Username"	

DriverName = "SQL Server"



Dim RegEdPath

RegEdPath= "HKLM\SOFTWARE\ODBC\ODBC.INI\" & DataSourceName & "\"



WshShell.RegWrite  RegEdPath  , ""

WshShell.RegWrite  RegEdPath & "Database" , DatabaseName

WshShell.RegWrite  RegEdPath & "Description" , Description

WshShell.RegWrite  RegEdPath & "Driver" , DriverPath

WshShell.RegWrite  RegEdPath & "LastUser" , LastUser

WshShell.RegWrite  RegEdPath & "Server" , Server

WshShell.RegWrite "HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\" & DataSourceName , DriverName

Msgbox "Successfully created DSN"

cleanup:

Set WshShell = Nothing

Set fso = Nothing

Set sysFolder = Nothing

Exit Sub

errhandle:

Msgbox Error() & " on row " & Erl() & " in Sub initialize()"

Goto cleanup	

End Sub

Subject: Create System DSN using LotusScript, Working sample

Wow, thanks. I was looking for this code about 3 weeks ago and couldn’t find it. Much appreciated.