Reputation: 85
I want to create ODBC DSN for a database (which will be included in my application folder whenever a user setups the application). I want to know how to create ODBC with all the required parameters so that the first thing that is done when the setup is being run is connecting the database to the application. I have tried using default VB.NET setup wizard and Installshield.
Upvotes: 2
Views: 4474
Reputation: 3168
I don't know any method to create DSN via installer or with VB.NET but using Windows utilities you can create one.
this page shows how to create DSN in Windows using command line utility odbcconf
so once you create a batch script that can create DSN according to your application requirements, you can trigger the batch to get executed before your setup copies files to the users computer. So after the script is executed, application installation will move further to copy remaining files and after installation completes, and application starts, your connection to the DSN will work as expected, since DSN is now created. I haven't worked with InstallShield though, my experience with NSIS says that executing batch script via installer will surely bring up the command prompt window during installation, which you might not want.
Another way to avoid showing command prompt window is to execute your batch script (in silent mode) upon first run of your application, before it establishes any connection to database. You can execute your batch file (.bat) without showing command prompt window using WScript.Shell
object as follows.
Dim batfile As String
batfile = "C:\Program Files\Your App\YouDSNCreationBatchFile.bat"
Set WshShell = CreateObject("WScript.Shell")
cmds = WshShell.RUN("""" & batfile & """", 0, True) 'All Quotes are necessary if file path contains folders with spaces in thier names
Set WshShell = Nothing
Though odbcconf
can also be used in VB directly to create DSN, but if you don't want to tweak your application code to create DSN before it connects, using batch script will be a fail-safe solution, however, as I guess, you might have connected your application in try
block, so if you catch exception which thrown due to lack of availability of DSN it required, this batch script can be called again to create one or prompt user for the same.
!!IMPORTANT: As MSDN page says, odbcconf
utility is likely to be removed from future versions of Windows Data Access Components, you should reconsider this method if you are using this for long-term.
Upvotes: 1