Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to work with ADO in VFP 6.0 ?

Status
Not open for further replies.

INFORMAT

Programmer
Jan 3, 2001
121
BE
Hello,

I'm a visual foxpro programmer. As database I use SQL server. For the connection between SQL server and VFP 6.0 I use a ODBC connection. This means that I have to make these ODBC connection on every computer where my program is running.
To solve this problem I tought to use ADO instead of ODBC.
I run the following code

oado =createobject('adodb.connection')
oado.connectionstring = "driver= {SQL server};server=
NTSERVER;uid=sa;pwd=mypassword;"
oado.open

When I run this code I get the following error at the last line (oado.open)

OLE|dispatch exception code 0 frm Microsoft OLE DB
Provider for ODBC drivers: [Microsoft][ODBC driver
manager]
Data source name not found and no default driver
specified.

Can somebody help me with these error ?

Thanks for your time and answer.

Devriendt Nico
Informat CV
Informat@unicall.be

 
Informat, you don't need to create DSN conection at each client computer. Following is a sample of connection to SQL Server using SPT commands:

* following are global defaults change
=SQLSetProp(0, 'DispLogin', 3)
=SQLSetProp(0, 'DispWarnings', .F.)
=SQLSetProp(0, 'Transactions', 2) && manual transactions

local lcConnString
m.lcConnString = "Server=MyServer;Driver=SQL Server;UID=sa;Passowrd=;Database=TESTDatabase"
THIS.nHandle = SQLStringConnect(m.lcConnString)

IF THIS.nHandle < 1
RETURN .F. &amp;&amp; cannot connect, you can use aerror()
&amp;&amp; to get more info from SQL Server why cannot connect
ELSE
* set some properties...
=SQLSetProp(THIS.nHandle, 'DispLogin', 3)
=SQLSetProp(THIS.nHandle, 'DispWarnings', .F.)
=SQLSetProp(THIS.nHandle, 'Transactions', 2) &amp;&amp; manual transactions
=SQLSetProp(THIS.nHandle, 'QueryTimeout', 50) &amp;&amp; 50 sec. query timeout
ENDIF

You can also create database manually and create connection in it manually without DSN just using connection string (similar as above in SQLStringConnect function). Than create remote views manually from some data table (it might be included into exe file as read-only) - here we go. You can find articles also about how to create views manually in some database. I recommend you also to search more information at and fox.wikis.com

You can find also here articles about how to make SPT cursor updatable. Let us know if you will have problems.


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Hi Devriendt,

As Vlad mentioned, you do have the option of using SPT.

To answer your question, Yes, it is possible to use ADO with VFP. One note of interest is that VFP does not surface COM events, so if you are planning on using ADO events, you'll need to explore the following:

VFPCOM Utility

I think your problem is that you forgot to specify the default database. Try:

oado.connectionstring = &quot;driver= {SQL server}; server=NTSERVER; uid=sa; pwd=mypassword; database=mydb&quot;

I would recommend bypassing ODBC altogether:
[ignore]
oado.connectionstring = &quot;Provider=sqloledb.1;Persist Security Info=False;User ID=sa;Initial Catalog=mydb;Data Source=NTSERVER;;password=mypassword;&quot;[/ignore]

Also, I would recommend the following article by John V. Peterson:

ADO Jumpstart for Microsoft Visual FoxPro Developers


Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Jonscott8 wrote:
>I would recommend bypassing ODBC altogether

Why? Performance? Security? Usability? Reliability?
Just curious...
-Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top