Is there a way in LotusScript to create an ODBC Data Source? I would like my program to check for the Data Source and if it doesn’t exist, create it. Has anyone done this? Any help would be greatly appreciated.
Thanks,
MJ
Is there a way in LotusScript to create an ODBC Data Source? I would like my program to check for the Data Source and if it doesn’t exist, create it. Has anyone done this? Any help would be greatly appreciated.
Thanks,
MJ
Subject: ODBC Data Source Question
the LS:DO classes do not have a method for creating. So you would be dependent on using a windows API to do that.
HTH – Cheers
Subject: ODBC Data Source Question
Yes, I do this in my app and it works just fine. Here is an example that sets up a dBase data source. Never mind all the references to custom objects like printqueue, just note that you have to register the win api call you’re going to make and then - this is the tricky part - pass all the right arguments. The arguments you pass in as a single string, called dbAttributes in this example. The arguments depend on the driver you are using, so go find the vendor’s documentation and good luck to you.
Declarations:
Declare Function SQLConfigDataSource Lib “ODBCCP32.DLL” (Byval hwndParent As Long, _
Byval fRequest As Long, _
Byval lpszDriver As String, _
Byval lpszAttributes As String) As Long
Const ODBC_ADD_DSN = 1 ’ Add data source
Const ODBC_CONFIG_DSN = 2 ’ Configure (edit) data source
Const ODBC_REMOVE_DSN = 3 ’ Remove data source
Sub Click:
Dim ws As notesuiworkspace
Dim uidoc As notesuidocument
Dim doc As notesdocument
Dim v As Variant
Dim ind As Variant
Dim sel As String
Dim flag As Integer
' Values used in setting up the new data source
Dim printqueue As printqueue
Dim dbAttributes As String
Set ws = New notesuiworkspace
Set uidoc = ws.currentdocument
' Figure out which print queue the user has selected in the listbox.
sel = uidoc.fieldgettext("LISTBOX")
If sel = "" Then Exit Sub
' An array of printqueue description strings:
v = printqueues.getDescription
ind = Arraygetindex(v,sel,5)
' Obtain the printqueue object corresponding to the string the user selected.
Set printqueue = printqueues.printqueue(Cint(ind))
dbAttributes = "COLLATINGSEQUENCE=ASCII"+Chr$(0)+_
"DEFAULTDIR="+printqueue.path+Chr$(0)+_
"DELETED=0"+Chr$(0)+_
"DSN="+printqueue.name+Chr$(0)+_
"DESCRIPTION="+printqueue.datasourcedescription+Chr$(0)+_
"DRIVERID=277"+Chr$(0)+_
"FIL=dBase IV"+Chr$(0)+_
"PAGETIMEOUT=600"+Chr$(0)+_
"READONLY=False"
flag = SQLConfigDataSource(0, ODBC_ADD_DSN, printqueue.drivername, dbAttributes)
If flag Then
printqueue.isinstalled = True
' Now push the new 'descriptions' into the form, so as to update the listbox.
' This changes <queuename> to <queuename (installed)>.
Set doc = uidoc.document
Call doc.replaceitemvalue("LISTBOXSOURCE", printqueues.getDescription)
Call uidoc.refresh
' Now re-select the current queue - that is, the queue the just installed - in the listbox.
' Its description will have changed from <queuename> to <queuename - (installed)>,
' and so to have it appear to remain selected we must reselect it using its new moniker.
'
' Note that we use the back end method here, so as to trigger the hide-when
' formula on the Install button. The effect of this is that user clicks the install button,
' the listbox updates, and the Install button disappears. (It will reappear when they
' click on some other listbox entry.)
Call uidoc.document.replaceitemvalue("LISTBOX", printqueue.getDescription)
Call uidoc.refresh
Else
Msgbox "Unable to install "+printqueue.name+". You will have to install it manually,"+_
" through the Windows control panel. See Help for instructions."
End If