Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Connect to DBC database
Message
From
01/11/2023 14:50:58
 
 
To
31/10/2023 11:59:16
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01687153
Message ID:
01687167
Views:
72
>>>>HI,
>>>>
>>>>I need to create a connection to Visual Foxpro DBC database for query specific table documentos and insert the result into Cursor for creating a new table on SQL server to insert the result of my cursor.
>>>>This is my code:
>>>>
>>>>LOCAL loConnection
>>>>loConnection = CREATEOBJECT("ADODB.Connection")
>>>>
>>>>
>>>>SET DATE BRITISH
>>>>
>>>>lcDBCPath = Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=D:\1.Bnext_Espanha\Orozco\EMP01\gestion.dbc;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO;
>>>>
>>>>
>>>>
>>>>* Attempt to establish a connection
>>>>TRY
>>>>    loConnection.Open(lcDBCPath)
>>>>    ? "Connected to the database successfully."
>>>>    * Now you can execute SQL commands and queries.
>>>>
>>>>    * For example, retrieve data from a table
>>>>    lcSQL = "SELECT * FROM documentos"
>>>>    loCursor = loConnection.Execute(lcSQL)
>>>>    ? loCursor.GetString()
>>>>
>>>>    * Don't forget to close the connection when done
>>>>    loConnection.Close()
>>>>CATCH TO loError
>>>>    ? "Failed to connect to the database. Error: " + loError.Message
>>>>ENDTRY
>>>>
>>>>
>>>>But i have this error:
>>>>Date/datetime contains illegal characters.
>>>>
>>>>Someone could help me , please.
>>>
>>>Surround the connectstring with quotation marks. It's trying to evaluate it as an expression, and the first thing after the equal sign is delimited with curly braces, which Fox tries to evaluate as a date expression.
>>>
>>>Hi Dragon,
>>>
>>>Please could you rewrite for me in correct way?
>>
>>Just this line:
>>
>>lcDBCPath = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=D:\1.Bnext_Espanha\Orozco\EMP01\gestion.dbc;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO;"
>>
>>Hi Dragan,
>>
>>Thanks to your reply, but VFP return this Error:
>>
>>Failed to connect to the database.Error: OLE
>>IDispatch exception code 0 from Microsoft OLE DB
>>Provider for ODBC Drivers:[Microsoft][Gestor de
>>controladores de ODBC] O nome da origem de dados não foi encontrado e não foi especificado
>>nenhum controlador predefinido..
>>
>>Do you an idea about why this error occur?
>
>My portuguese would need a lot of WD-40, but from what I see it's either something in the path to the dbc (rights to open it from the app?) or you simply don't have the ODBC driver installed (most probably, it doesn't come with any of them windowses for the last ten years at least).
>
>Why bother with ODBC to a dbc, when you can simply select * from whichever table you want, get your cursor, and do the rest the same as before?

If the aim is to switch backends, drivers or datasources
this approach (OLEDB to parse SQL and fire off backend
instance code) is not THAT bad.

It sidesteps the vfp ODBC driver problems and perf is not bad...
Other option is Advantage ODBC, if Cursoradapter does not fit.

Raw vfp SQL possible and least amount of work,
but I often work through CA just to be certain
I am not handling the base table.

But if working from Dotnet or through COM
(Python or other) this cuts down Marshalling.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform