ODBC DSN Maker.WBT
Keywords: ODBC DSN Maker.WBT
What follows is a script I wrote to create ODBC DSNs automatically. I used CallDll() and it worked without a 'hitch'. The sample script will create an ACCESS 97 blank database from scratch. By expanding the parameters it should be straightforward to create system or user DSN's which point to the blank file just created.Notice I referred to DBV3 in my CREATE statement as undocumented. This has to do with the MDAC 2.1 drivers (4.x) where the default in the driver manager is for a 4.x version of ACCESS - if you use DB instead of DBV3 with 4.x drivers, you will create a blank MDB ~ 65k in size but you cannot open it with ACCESS 97.
It, of course, follows that DBV2 will create an ACCESS 2.0 compatible file.
;Winbatch - Create 'blank' ACCESS 97 Database ;Purpose - Using special call to SQLConfigDataSource() ;Author - Stan Littlefield ;param1 | Path+MDB Name ;Example:winbatch.exe sqlcfg C:\TEMP\STAN.MDB If FileExist("%param1%") == @TRUE Message("FILE ALREADY EXISTS","%param1%") exit Endif ;AddExtender("wwodb32i.dll") cDriver="Microsoft Access Driver (*.mdb)" ;Return Codes SQL_FALSE = 0 SQL_TRUE = 1 ;here are the types of operations that can be performed ODBC_ADD_DSN =1 ; Add data source ODBC_CONFIG_DSN =2 ; Configure (edit) data source ODBC_REMOVE_DSN =3 ; Remove data source ODBC_ADD_SYS_DSN =4 ; add a system DSN ODBC_CONFIG_SYS_DSN =5 ; Configure a system DSN ODBC_REMOVE_SYS_DSN =6 ; remove a system DSN cString="CREATE_DBV3=" ; undocumented feature cString=StrCat(cString,"%param1%" ) cString=StrCat(cString,Num2Char(0) ) ;add null-terminator x = DllCall("C:\WINNT\SYSTEM32\ODBCCP32.DLL", long:"SQLConfigDataSource",long:0,long:ODBC_ADD_DSN,lpstr:cDriver,lpstr:cString) If x<>SQL_TRUE Message("SQL FAILED",x) Endif
Article ID: W14775