Link to home
Start Free TrialLog in
Avatar of Aquadp
Aquadp

asked on

why i can't use ADO to open DBF file in WIN-XP?

My Code:
...
function TDMCenter.OpenDBFDatabaseFile(FilePath,
  FileName,Conditions: String): Boolean;
begin
  Result := True;
  try
    qryDBFdest.Close;
    qryDBFdest.ConnectionString:='Provider=MSDASQL.1;'
                                +'Persist Security Info=False;'
                                +'Extended Properties='
                                +'"Driver={Microsoft Visual FoxPro Driver};'
                                +'UID=;'
                                +'SourceDB='+ FilePath + ';'
                                +'SourceType=DBF;'
                                +'Exclusive=No;'
                                +'BackgroundFetch=Yes;'
                                +'Collate=Machine;'
                                +'Null=Yes;'
                                +'Deleted=Yes;"';  
    qryDBFdest.SQL.Clear;
    qryDBFdest.SQL.Add('SELECT * FROM '+FileName+Conditions);
    qryDBFdest.Open;
  except
    Result := False;
  end;
end;
...

when my application run in WIN2000 no error,but in WIN-XP,the application always show error that couldn't open the DBF file.

why????:(how to modify my code.please help me
Avatar of andrewjb
andrewjb
Flag of United Kingdom of Great Britain and Northern Ireland image

Shouldn't it be FilePath + "\" + FileName?

oops.

"\\"
Ok. Maybe not.

Have you checked the path and file exist?
Does it work if you put a query on a form and use the wizard to set the connection string?
Do you have the right permissions to read/write the file in XP?
ASKER CERTIFIED SOLUTION
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aquadp
Aquadp

ASKER

i sure the path is exist.

i call the function code:
my dbf file path:C:\dbf\mytable.dbf

OpenDBFDatabaseFile('C:\dbf\','mytable','');

i used ADOQuery.i have another test application(.exe) that can open dbf file in XP.
so i think my code is fault.
perhaps it should be mytable.dbf instead?
Avatar of Aquadp

ASKER

no ,it couldn't be mytable.dbf.

experts, please help me.
Try:
  qryDBFdest.SQL.Add('SELECT * FROM '+FileName+' '+Conditions);
Perhaps the space is missing?
Avatar of Aquadp

ASKER

i said,my program run in win2000 is ok,but run in winxp show error.

i think i should modify code below:
    qryDBFdest.ConnectionString:='Provider=MSDASQL.1;'
                                +'Persist Security Info=False;'
                                +'Extended Properties='
                                +'"Driver={Microsoft Visual FoxPro Driver};'
                                +'UID=;'
                                +'SourceDB='+ FilePath + ';'
                                +'SourceType=DBF;'
                                +'Exclusive=No;'
                                +'BackgroundFetch=Yes;'
                                +'Collate=Machine;'
                                +'Null=Yes;'
                                +'Deleted=Yes;"';

but i dont know where i should modify?(perhaps ODBC ,db driver or other drivers's error )
Could I ask again...
Does it work if you put a query on a form and use the wizard to set the connection string?

i.e. where did this connection string come from?
On your XP system, go to "Settings/Control panel/Administrative tools/ Data sources (ODBC)" and check for the existance of the "Microsoft Visual FoxPro Driver". Just to make sure it's there...

Now, on my W2K system, I made an ADO connection to some folder with the connection wizard and I get the following connection string:
  Provider=MSDASQL.1;Persist Security Info=False;Extended Properties="DSN=Visual FoxPro-database;UID=;SourceDB=d:\;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"

Apparantly, I don't get one with the "Driver=Microsoft Visual FoxPro Driver}" that you seem to get. At least, this confuses me a bit...
Avatar of Aquadp

ASKER

i checked that "Microsoft Visual FoxPro Driver" exists on my xp system.

i changed my code into yours."Extended Properties="DSN=Visual FoxPro-database;"
but i try it and result is false.