Jump to content

Creating System DSN's with AutoIt


Recommended Posts

Hello,

I'm trying to create a System DSN with AutoIt. This works for Microsoft Excel but I need it for Visual FoxPro. I can't get the latter to function. After a few of those hours I decided to call in the real experts ;-)

The main function is called GetAll() and can be found at the bottom of the script attached to this topic.

This function states:

;This line does work

ConfigDS($CfgOptions[0][0],$CfgOptions[0][1]) ;Create Excel Datasource

;I'd like the line below to work

ConfigDS($CfgOptions[4][0],$CfgOptions[4][1]) ;Create FoxPro Datasource

What I figured out is:

* The DSN is created if all the parameters but the DSN name are passed

* So there must be something wrong with the separator

* The following separators won't work either ; | chr(0)

* chr(0) as a separator is not possible since the string is then terminated

The following command works in a command line box:

odbcconf /a {configsysdsn "Microsoft Visual FoxPro Driver" "DSN=TestMyDataSource|Description=Test;SourceDB=D:\DATABASE\database.dbc|SourceType=DBC|Exclusive=Yes|BackgroundFetch=Yes|Collate=Machine|Null=No|Deleted=Y

es"}

Whether the DSN is created can be checked on the System-DSN tab after running odbcad32.

P.S.: The script in general is from another forum topic somewhere around here. I added the Visual FoxPro part myself.

AutoIt_create_DSN.au3

Link to comment
Share on other sites

@ptrex

Thanks for the reply. I cannot get it working with only the info you provied. I created a new script consisting of two commands only. It returns: Error: The requested action with this object has failed. This is the script:

$oConn = ObjCreate ("ADODB.Connection")

$oConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _

"SourceType=DBC;" & _

"SourceDB=D:\database\database.dbc;" & _

"Exclusive=Yes"

What I'm trying to do is check if the database can be opened exlusive. Then I might run a select on the database and that's about it. I cannot get the connection with Visual FoxPro working however (weird is that the Excel connection does work).

I'd also like the script to run on a computer with as little installed as possible. ADODB requires more than ODBC, isn't this a fact?

Link to comment
Share on other sites

@thefounder

I'd also like the script to run on a computer with as little installed as possible. ADODB requires more than ODBC, isn't this a fact?

Accrding to my knowledge the ADODB is available on every windows by default.

So nothing to install.

What the error concernes, I can"t test becauise I don't have a VFP around.

Use this COM error check to debut the error.

; begin of the script
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

; your code here


; end of the script
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(1) ; to check for after this function returns
Endfunc

regards

ptrex

Link to comment
Share on other sites

@ptrex

Accrding to my knowledge the ADODB is available on every windows by default.

So nothing to install.

=> OK, thanks for the info.

What the error concernes, I can"t test becauise I don't have a VFP around.

=> a MSI can be found here: http://msdn2.microsoft.com/en-us/vfoxpro/bb190233.aspx

The COM returned an error indeed: 80020009. Uploaded as a screenshot. I Googled this errorcode but it did not help me get any further.

Link to comment
Share on other sites

  • 5 years later...

Hello,

I'm trying to create a System DSN with AutoIt. This works for Microsoft Excel but I need it for Visual FoxPro. I can't get the latter to function. After a few of those hours I decided to call in the real experts ;-)

The main function is called GetAll() and can be found at the bottom of the script attached to this topic.

This function states:

;This line does work

ConfigDS($CfgOptions[0][0],$CfgOptions[0][1]) ;Create Excel Datasource

;I'd like the line below to work

ConfigDS($CfgOptions[4][0],$CfgOptions[4][1]) ;Create FoxPro Datasource

What I figured out is:

* The DSN is created if all the parameters but the DSN name are passed

* So there must be something wrong with the separator

* The following separators won't work either ; | chr(0)

* chr(0) as a separator is not possible since the string is then terminated

The following command works in a command line box:

odbcconf /a {configsysdsn "Microsoft Visual FoxPro Driver" "DSN=TestMyDataSource|Description=Test;SourceDB=D:DATABASEdatabase.dbc|SourceType=DBC|Exclusive=Yes|BackgroundFetch=Yes|Collate=Machine|Null=No|Deleted=Y

es"}

Whether the DSN is created can be checked on the System-DSN tab after running odbcad32.

P.S.: The script in general is from another forum topic somewhere around here. I added the Visual FoxPro part myself.

translated by google (sorry for mistakes) (PTBR)

I know it is another matter but who knows with their esperiencias would possibly help me.

I have a program in foxpro done by others and can control it perfectly but I would make sure the current focus.

I can get the handle of the current form but do not know where I'm joined field.

Control only send () and sleep (500) between ({TAB}) sent for each registration but I would be sure to identify which field I am really alert by current focus.

x, y coordinate of the field or Handle field name or if there

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...