How to use vfpoledb - oledb

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;"

Related

FireDAC (FDQuery) - database with dot in it's name

I have got this problem with FireDAC -> FDQuery component when it tries to select data from a database with '.' (dot) in its name.
The database name is TEST_2.0 and the error on Opening the dataset says:
Could not find server 'TEST_2' in sys.servers [...]
I have tried {TEST_2.0} (curly brackets) and [TEST_2.0] (square brackets). Also setting QuotedIdentifiers (Format Opetions) property to True does not seem to fix the problem. In SQL query I can add 'SET QUOTED_IDENTIFIER ON;' but this breaks inserts to the dataset.
The FDConnection component can connect to that server and that database using MSSQL driver without problems. It seems it is the dataset that dosn't handle it. UniDAC seems to handle everything without any problems.
I am using RadStudio 10.2.
Has anyone found any solution to this? Thanks in advance for any replies
I got a response from Emarcadero and it works for me:
"The problem is not in FireDAC, but in SQL Server ODBC driver
SQLPrimaryKeys function. It fails to work with a catalog name
containing a dot. FireDAC uses this function to get primary key fields
for a result set, when fiMeta is included into FetchOptions.Items. So,
as a workaround / solution, please exclude fiMeta from
FetchOptions.Items."
What is wrong?
I was able to reproduce what you've described here. I've ended up on metainformation command, specifically the SQLPrimaryKeys ODBC function call. I have used SQL Server Native Client 11.0 driver connected to Microsoft SQL Server Express 12.0.2000.8, local database server instance.
When I tried to execute the following SQL command (with TEST_2.0 database created) through a TFDQuery component instance with default settings (linked connection object was left with empty database connection parameter) in Delphi Tokyo application:
SELECT * FROM [TEST_2.0].INFORMATION_SCHEMA.TABLES
I got this exception raised when the SQLPrimaryKeys function was called with the CatalogName parameter set to TEST_2.0 (from within the metainformation statement method Execute):
[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL
Server]Could not find server 'TEST_2' in sys.servers. Verify that the
correct server name was specified. If necessary, execute the stored
procedure sp_addlinkedserver to add the server to sys.servers.'.
My next attempt was naturally modifying that CatalogName parameter value to [TEST_2.0] whilst debugging, but even that failed with similar reason (just failed for the name [TEST_2), so for me it seems that the SQLPrimaryKeys ODBC function implementation with the driver I've used cannot properly handle dotted CatalogName parameter values (it seems to ignore everything after dot).
What can I do?
The only solution seems to be just fixing ODBC drivers. Workaround I would suggest is not using dots in database names (as discussed e.g. in this thread). Another might be preventing FireDAC from getting dataset object metadata (by excluding fiMeta option from the Items option set). That will bring you the responsability of supplying dataset object metadata by yourself (at this time only primary key definition).

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.

Missing table in Visual FoxPro DB

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.

How to call a stored procedure in IBM System i Access for Windows GUI Tool

I would like to test a DB2 stored procedure running on an AS400 system.
I have the IBM System i Access for Windows installed and can run SQL commands against the DB2 database.
My question is: What is the syntax to execute a stored procedure that takes in a parameter and returns a result as an output parameter and print the value to the screen?
Just to clarify: I am not asking how to call the proc in code. I want to execute the proc and see the results in the gui tool (which is similar to SQL Enterprise Manager).
use the keyword call and pass in the parameters.
call myStoredProc(parm1, parm2, ?);
for more details see here http://www.ibm.com/developerworks/data/library/techarticle/dm-0503melnyk/. The interesting part is Figure 5. Using the Command Editor to call an SQL procedure
What you want is possible. I have done it myself many times. Unfortunaly, I'm not at the office right now so it must be from the top of my head.
Start System i Access
Go to your iSeries icons and log on to the one where your stored procedure lives
Go to the databases icons and connect to the correct one (you've one local and probably one or more remotes)
Only then, you will see the option "run SQL script" at the bottom of your screen
Start that option and you will see a SQL editor (editor on top, viewer/messages at the bottom)
Remember that you are already connected to the correct iSeries but your JDBC request will get the *LIBL of the userprofile of your connection. Therefore you must know the schema (iseries library) of your stored procedure
Enter "call YOURSCHEMA.YOURSTOREDPROCEDURE(?,?);" and use the menu or shortcut to run that statement. Notice that - depending on your JDBC settings (see menu) - the correct syntax may be "/" instead of ".". Also, notice that you can replace the first question mark with a value.
On an additional note,
In iAccess, under every schema you will see icons for the tables, views and so on. Also an icon for stored procedures is available. You will see your SP there. Use the options to see the definition and so. This information includes detailed information about the parameters
If you want to check that on your iSeries, use the system catalog (this can be done from the SQL editor too) with "select * from qsys2.sysprocedures where procedure_name (sorry, not sure about the name of this column right now) = 'YOURSTOREDPROCEDURE';"
VERY IMPORTANT: I was never able to test the SP with the SQL editor (STRSQL) on the iSeries itself. Only the iAccess SQL editor did work correctly.
You should be able to run your SP like this:
DECLARE
usr_in YOUR_TABLE.YOUR_COLM%TYPE; --Gets the correct type by looking at column type
app_in YOUR_TABLE.YOUR_OTHER_COLM%TYPE;
BEGIN
usr_in:='some value';
app_in:='another_value';
YOUR_SP_NAME(usr_in, app_in);
END;
Or you can use EXECUTE, but it can't be dynamically prepared (not run in Java) and I think there's some other disadvantages.
EXECUTE myStoredProc(parm1, parm2, ?);

Resources