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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC Data Sources with VFP 2

Status
Not open for further replies.

Guntruck

Programmer
Mar 29, 2001
25
US
I am developing an application for totally clueless autobodyshop workers. I need to be able to access a MS SQL 7 server to work with data. I know you have to have a system DSN ODBC setup to get that to work. I wanted to know if anybody had any infomation on how I could automatically setup ODBC sources from VFP so I dont have to answer the phone 10,000,000 times to explain how to to these helpless saps.


Thanks,

Dave
 
No, you don't need to setup a DSN to connect to SQL Server from VFP. See the faq: faq184-65

Basically, you create a connection string and use the SQLSTRINGCONNECT command, as in this example:

[tt]nConnection = SQLSTRINGCONNECT("driver={SQL SERVER};SERVER=172.38.216.36;UID=myuser;PWD=mypwd;DATABASE=mydatabase;Trusted_Connection=No")
[/tt]

Note that in the above, the semicolons are not line continuation characters but are part of the connection string. Robert Bradley
teaser.jpg

 

I really like the use of views and my program so far makes good use of them. Is there any way I can use this string connection... with a view?? Or is that not possible, the faq says that its for use with SPT..

Thanks,

dave
 
Ok, Great that works very well, yet one more question, does the connetion string have to be set in stone? Is there a way I could modify the connetions I have while the program is running? I just want to be able to change the address of our SQL server without having to recomplie and distribute 200000 copies of this client... Also, do you know why when i try to create a new record in a table that does not allow null values in a column it gives me an error that says it couldnt insert the row because i tried to give it a null value, but all the columns are filled in.... just kinda lost on that one...

dave
 
Is there a way I could modify the connetions I have while the program is running?

I'd just store whatever data might change in a table external to your exe which can be changed after installation. You could even have a popup to let the user locate the database for you if it isn't found where the table says it is. -- Dave
 
Yes, Thats exactly what I wish to do, but can i have variables in the connectionstring of my SQl connection for my views??


Dave
 
can i have variables in the connectionstring of my SQl connection for my views??

Sure. If you'll notice, the connect that Robert gave as an examaple was:

Code:
nConnection = SQLSTRINGCONNECT("some_string").

This "some string" can be constructed by the usual string concatination rules. You might have to use [some_string] instead of "some_string" or something like that, but it shouldn't be that tough to figure out. Of course, you'll have to create a new connection string each time the data changes, but I'm sure that wouldn't be often. Certainly not more than once a session, so just run the code for creating the connection when you start the program and that should be sufficient. --Dave

 
Ok, sorry I was just not understanding what you were saying.. thanks alot. any ideas on why SQL thinks in trying to insert null values when they arent null in my grid?


dave
 
any ideas on why SQL thinks in trying to insert null values when they arent null in my grid?

Could you give us the code which results in the error? Are you using a standard
Code:
 INSERT INTO ... VALUES ...
or something else? Perhaps you could have the name of one of the fields / variables you're trying to use spelled wrong. BTW, that's one of the things I liked about the later versions of Visual Basic; you could easily set it up so you couldn't misspell variables. I'm not sure if VFP will allow that in version 7 or not. -- Dave


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top