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

Invalid Handle Error

Status
Not open for further replies.

jortego

Programmer
Oct 14, 2002
16
US
This is sort of a repeat question from yesterday. Sorry, but I am really stumped.

I am using the following code that is inside of a procedure that is being called by a button on a form:

STORE SQLCONNECT('db_data') TO gnConnHandle
SQLEXEC(gnConnHandle, str_sql, 'MyCursor')
SQLDISCONNECT(gnConnHandle)

//db_data is my generic text FoxPro database.
//str_sql is my Characeter String Variable with my SQL statement.

It worked fine until I added a comment below it. Then I got a "Connection handle is invalid" error. By someone's suggestion yesterday, I changed the SQLCONNECT command to be SQLCONNECT('db_data', 'sa', ""). Again, it worked fine at first. So just to test it, I put a blank line in the code and I got the same error. I also tried giving the full path of db_data and got the same result.

I am wondering if I am not properly executing or closing this connection. It seams very strange that the code fails to work once I add anything else.

Any Advice?

 
What are you using for comment marks?

From the above it looks like you are using // .

The backslashes are not comment characters, at least not in vfp6.

Comment with the following for entire line to be commented from the beginning. ( * or *!*)

* comment
*!* comment using the right mouse click comment, good for *!* alot of lines at once

Or for end of line comment use &&, example:
private iNum && comment, iNum is number fo kids

Hope this takes care of the problem.

JDemmer
God Bless
 
I am using "*" for comments. I just put those // marks in my message as a habit from coding other things.

However, even when I remove all comments and just insert a blank line or additional code, I still get the same results.

Thanks for the input.
 
have you tested the gnConnHandle for a valid return of a postive number?

also the 'db_data' name has to be as defined in your Odbc.ini file Attitude is Everything
 
I must plead ignorance on the Odbc.ini file. How do define my datasource name in this file?
 
jortego,
There are a couple ways to do this.

First:
I set the connection properties in my database container.
I have DBC with many tables (dbf's).

After you open the database container, in the menu choose Databases|connections. This will bring up the Connection Designer. If you do not have one defined you can use "new" to create one.

For instance, I have a vfp6 connecting to sql 2000. This is my connect string in the connection designer.

DRIVER=SQL Server;SERVER=DEVSERVER;APP=Microsoft® Visual FoxPro®;WSID=MYCOMPUTERNAME;DATABASE=MYDB;Trusted_Connection=Yes


Second:
use code to set connection

another example:
create connection mydb connstring "DRIVER=SQL Server;SERVER=devserver;UID=mydb;PWD=password;DATABASE=mydb"

I am not the Whiz on this, a co-worker helped me get started.

You might look at the help at Create Connection. syntax is:
CREATE CONNECTION [ConnectionName | ?]
[DATASOURCE cDataSourceName]
[USERID cUserID] [PASSWORD cPassWord]
[DATABASE cDatabaseName]
| CONNSTRING cConnectionString]

Hope this will get you started.

JDemmer
 
JDemmer, Thanks for the advice. It was very helpful.

But, at this point, there is something subtle that I must be missing. I followed your 1st example. I get a connectivity error when trying to connect to my .dbc file. Oddly enough, I was able to connect to the dbf talbes associated with dbc as well as to another dbc file that was already on the PC that I am using. I even created a new project with a new database and I was able to connect to it. The only thing I can't connect to is the dbc that I created for this project.

I suppose I could rebuild my Database and see if I can then connect to it. But now I am curious as to what's causing the connection problem so that I don't run into it again.
 
jortego,
Like I said I had a co-worker to fall back on.

I know I played with several different parameters before I got it right.


Without knowing alot of details about your app and the database or specifically what the error is that you are getting I won't be any help. It is curious though.

Let me know what the error is.

Jdemmer

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top