Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create Connection / SQLConnect
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00161962
Message ID:
00161976
Views:
20
>Using VFP 6.0 / Win 95.
>
>This is my first attempt at ODBC and I'm trying to programatically make a connection to an Access database after having gotten the database name and path from the user.
>
>Everything either to go smoothly but then the SQLConnect command will not make a connection or else the Create Connection command will cause the Connection Designer to pop-up which I don't want the user to have to see.
>
>Here is one of my many attempts that looks like it should work but it doesn't.
>
> OPEN DATABASE c:\MyDirectory\MyDB.dbc EXCLUSIVE
>
> lcConnString = 'DSN=My Access 7.0;'
> lcConnString = lcConnString + 'DBQ=C:\MyDirectory\MyAccess.mdb;'
> lcConnString = lcConnString + 'DefaultDir=C:\MyDirectory;'
> lcConnString = lcConnString + 'Driver={Microsoft Access Driver (*.mdb)};'
> lcConnString = lcConnString + 'DriverId=25;' && Access
> lcConnString = lcConnString + 'FIL=MS Access;'
> lcConnString = lcConnString + 'UID=admin'
>
> CREATE CONNECTION AccessTst1 CONNSTRING lcConnString
>
> gnConnHand=SQLCONNECT('AccessTst1')
>
>
>Can anybody tell me what's missing here? The example above will still ask the user for the Data Sourse Name and database to connect to even though they are listed in the Connection String.
>
>Any Help would be appreciated.
>
>TIA
>

First, do not use the PRE tags around your message. Only use them around code you want to leave as formatted.

You only need to create the connection in the DBC once. Use the Connection designer to do this. But first, you need to create a DSN via the ODBC Administrator found in the Control Panel. Once you create the DSN, you will identify this as the data source on the Connection designer.

You can browse the Win95 Registry to see what is entered for the DSN. Look in HKEY_CURRENT_USER\Software\ODBC\ODBC.INI

To do this by code, I did the following for a VFP DSN:
lcODBCDriver="Microsoft Visual FoxPro Driver"
lcSettingString = ;           "SourceDB=\\MyServer\VOL2\APPS\PIMS99\DATA\Pims.dbc"+CHR(0)+;
    "DSN=PCPIMS"+chr(0)+;
    "Description=VFP Pims!Roster"+CHR(0)+;
    "SourceType=DBC"+CHR(0)+;
    "BackgroundFetch=Yes"+CHR(0)+;
    "Exclusive=No"+CHR(0)+;
    "Collate=Machine"+CHR(0)+;
    "SetNoCountOn=No"+CHR(0)

#define  ODBC_ADD_DSN            1
#define  ODBC_CONFIG_DSN         2
#define  ODBC_REMOVE_DSN         3
#define  ODBC_ADD_SYS_DSN        4
#define  ODBC_CONFIG_SYS_DSN     5
#define  ODBC_REMOVE_SYS_DSN     6
#define  ODBC_REMOVE_DEFAULT_DSN 7

DECLARE Integer SQLConfigDataSource in odbccp32 ;
   Integer, Integer, String, String

local lnSuccess
lnSuccess=SQLConfigDataSource(0,ODBC_ADD_DSN,lcODBCDriver,lcSettings)
return iif(lnSuccess > 0, .t., .f.)
The lcODBCDriver is the exact description of the driver to use. In your case, it will be the description of the Access drivers. You can find this in the Registry as well.
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform