Missing table in Visual FoxPro DB - oledb

I'm using VFPOLEDB to connect to an VFP database (directory of dbf files).
Once connected, I manually create a table using:
create dbf critera(field_name c(30))
At this point, I verify a new dbf file is created in the database directory. I then try to query the new table, it should return no rows.
select * from criteria
I am presented with the following error:
File "criteria.dbf" does not exit.
Strange, eh?
So I manually delete the DBF file (VFPOLEDB doesn't support drop) and then run the following query.
create db criteria(field_name c(30)); select * from criteria
And get no error, no results returned as expected.
What gives? Any suggestions?

First, (could be a type-o), you had
create dbf Critera (missing the "i")
and then
select * from Criteria (has the "i")
If not that... for your connection string, are you just connecting to the PATH that the .dbf files will be located, or are you explicitly connecting to a path and database.
If just a path
string YourVFPConnectionString =
"Provider=VFPOLEDB.1;Data Source=c:\\SomePath\\WhereDataIs\\";
Or with a specific database container
string YourVFPConnectionString =
"Provider=VFPOLEDB.1;Data Source=c:\\SomePath\\WhereDataIs\\YourDatabase.dbc";
It might be easier to test just by pointing to the directory. The VFP OleDB provider will consider the path the root for any tables queried vs a full .dbc (database container) which could give you access to other stored procedures and such.
The OleDb doesn't support "DROP TABLE". You can still delete a file by running an ERASE "Criteria.dbf" via the OleDbCommand's ExecuteNonQuery()
As for the last one, VFP doesn't utilize the ";" as a break between statements like other SQL engines do where you could send a series of queries all together one after another. ";" in VFP is considered a "this command continues on the next line", and should have thrown an exception is it wouldn't have been able to process it.

Related

How to use FileTable in EF Code First

I'm using FileTable in SQL Server 2014 and EF code first in my project.
When I use this command
USE [master]
GO
ALTER DATABASE [OnlineStore]
SET FILESTREAM( DIRECTORY_NAME = N'OnlineStore',
NON_TRANSACTED_ACCESS = FULL) WITH NO_WAIT
GO
it shows this warning in sql
When the FILESTREAM database option NON_TRANSACTED_ACCESS is set to FULL and the READ_COMMITTED_SNAPSHOT or the ALLOW_SNAPSHOT_ISOLATION options are on, T-SQL and transactional read access to FILESTREAM data in the context of a FILETABLE is blocked.
Now I continue and create the table, and insert folder and file not problem.
My problem to read data, when read data is show this error:
Msg 33447, Level 16, State 1, Line 2
Cannot access file_stream column in FileTable 'File', because FileTable doesn't support row versioning. Either set transaction level to something other than READ COMMITTED SNAPSHOT or SNAPSHOT, or use READCOMMITTEDLOCK table hint.
I'm using EF code first - how to resolve this problem?
You must run this command to have the ability to SELECT the table.
USE [master]
GO
ALTER DATABASE [dbname] SET READ_COMMITTED_SNAPSHOT OFF WITH NO_WAIT

How can I create SSIS using stored procedure?

A group in my company granted me access to execute a stored procedure, and the stored procedure, if executed from excel, gives me a table. I want to store this table in SQL via SSIS.
I tried this via:
Within DFT, I created a connection using SQL Server Native Client. And within source assissstant, I entered SQL command
EXEC [dbname].[storedprocedure]
But then it returns an error:
No column information was returned by the SQL command.
Is there anyway to make this work?
Add the proper data source and then connect it to the OLE DB Command. Under the Connection Manager tab, setup your connection. Under the Component Properties Tab in the SqlCommand line enter EXEC [Stored Procedure Name] ? use as many ?s for as many variables declared in your Stored Procedure. Under the Column Mappings tab you will map your variables from the Stored Procedure to the relevant columns in your SQL Server DB.

SSIS - Use file name parameter in SQL Lookup Command (JET OLEDB)

Can I parameterise the SqlCommand in a Lookup Transformation when using the Jet engine against a CSV file? Is there another way to work with CSV's and Lookups?
I have a JET OLEDB connection that uses an expression to get the folder location from a variable as follows:
"Data Source=" + #[User::SourceRoot] + ";Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=\"text;HDR=Yes;FMT=Delimited(,)\";"
Then in my SSIS Lookup Transformation I have the following SqlCommand:
SELECT * FROM Users.csv
This works fine, however, I don't want to hard-code "Users.csv". Is there a way to configure this? I've tried setting partial cache, but haven't had any luck using the Advanced screen "Custom query" or using a '?' parameter in the query. (I'm using SQL 2012).
I would create a data flow task that uses a flat file connection manager to read from the CSV and load that to a cache transformation. Then you can use the cache transformation file in the lookup task.

How can I create a D-Base IV table using Delphi ADO components please?

I am working on the software for an instrument that logs batch results into single DBase 4 (*.dbf) disk files in a folder. In preparation for adding new logging analysis capability which is planned to work with multiple of these DBF files, I am changing the existing simple BDE TTable and CreateTable which reopen and create a new DBF file respectively into use of the Delphi ADO components.
Using other suggestion here on SO I have successfuly created a test application which opens an existing DBF file using the following core code using a TAdoDataSet and a TAdoConnection:
ADODataSet1.DisableControls;
try
S := ExtractFileDir( ParamStr(0) ); //set the dbf folder location here
ADOConnection1.LoginPrompt:=false;
ADOConnection1.ConnectionString:=Format('Provider=Microsoft.JET.OLEDB.4.0;Data Source=%s;Extended Properties=dBase IV;',[S]);
ADOConnection1.Connected:=True;
ADODataSet1.CommandText:='Select * from test.dbf'; //The SQL query uses the name of the dbf file
ADODataSet1.Open;
finally
AdoDataSet1.EnableControls;
end;
This works fine but before my DBF is used for the first time I will also need to creat an empty DBF file ready to add my log records. I could do this by opening an exising 'empty' DBF file each time but I was hoping that there was an SQL? way of creating my file if I have already created and defined my fields (which is easy for me). I tried this with a TAdoTable where I could created the required fields but I could not find any examples of how to get this table structure out onto disk when nothing was already there, mainly because there are so many ADO examples but almost always working on existing data tables.
Can anyone help me create a sample DFB table file with a couple of fields using ADO components please? I'm sure I can then build on that.
Many Thanks.
Use TADOCommand and execute Create Table SQL, for example something like this :
Create Table Test (TestField1 char(64), TestField2 integer)

How to use vfpoledb

I have installed vfpoledb I am running it against VFP 8 tables. When I execute the command
connection = SQLSTRINGCONNECT([Provider=vfpoledb;Data Source=C:\temp\;Collating Sequence=general;])
I get a popup dialog with SELECT DATA SOURCE
I am trying to use the connection string specified here http://www.connectionstrings.com/visual-foxpro#89 where I want access to free tables using OLEDB. I can connect using an ODBC connection string.
Am I using it correctly?
You don't specify the language you are trying to build against. Here's another link of an instance using OleDB to connect to VFP Tables
It may not be a perfect match, but does show how to properly create an OleDB connection to the path where the VFP data exists, and perform a SQL-Insert using parameterized queries (prevent sql injection), and attempting to pack/delete from too.
Once you get the basic connection down, and basics on parameterizing queries, your queries can be like almost any other VFP SQL-Select, Update, Delete query.
From within Foxpro you need to use the ADODB connector:
oConn = CREATEOBJECT("ADODB.Connection")
oConn.ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\temp\;Password="";Collating Sequence=MACHINE;"

Resources