Jump to content

This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.

DSN Creation

2 replies to this topic


  • Members
  • 25 posts

Posted 07 December 2005 - 14:19

I am able to create the DSN using the ODBC Resources but my requirement is that needs to be created dynamically since the customer can provide/maintain the DSN in any name.

So I created one custom dialog which accepts the DSN information. Now I want to create the DSN using the given value. How to do that?

Your help would be appreciated.


  • Members
  • 1 posts

Posted 11 July 2006 - 22:34

You can create the DSN by writing to the Windows Registry.

Below is a vbs example, that you can use for inspiration.

User DSN's are written into HKCU.
System DSN's are written into HKLM.

'--------------------- script begin
Dim DataSourceName
Dim DatabaseName
Dim Description
Dim DriverPath
Dim DriverName
Dim LastUser
Dim Server

Const SystemFolder= 1
Dim fso
Dim SysFolder
Dim SysFolderPath

DataSourceName = "DSNName" 'Change this
Description = "Data Source Description" 'Change this
Server = "ServerName" 'Change this
LastUser = "DBUser" 'Change this
DriverName = "SQL Server" 'Do NOT change the driver name if using SQL Server.

Set fso = wscript.CreateObject("Scripting.FileSystemObject")
Set SysFolder = fso.GetSpecialFolder(SystemFolder)
SysFolderPath = SysFolder.Path

DriverPath = SysFolderPath & "\sqlsrv32.dll"

Set WshShell = WScript.CreateObject("WScript.Shell")

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

WshShell.RegWrite RegEdPath , ""

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


'----------------- script end

Best Regards
Mikael Sorensen


  • Full Members
  • 48 posts

Posted 12 July 2006 - 13:21

Or if the aforementioned is not satisfactory you can use ODBC programming (the sample is from MSDN). Yes you need to "import it " to script but is simple and even you can find on the sample part of this site the code I think.

#include <stdio.h>
#include <windows.h>
#include "sql.h"
#include <odbcinst.h>

int main()
RETCODE retcode;

UCHAR *szDriver = "SQL Server";
UCHAR *szAttributes =

retcode = SQLConfigDataSource(NULL,