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!

ODBC in powerbuilder using a INI file??

Status
Not open for further replies.

viper2003

Programmer
May 5, 2003
7
US
I have an application running in powerbuilder 9 using a microsoft access database, here is the connection code I use in my main window open event
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = "ConnectString='DSN=DB1',ConnectOption='SQL_OPT_TRACEFILE,D:\development\powerbuilder9\latin\SQL.LOG'"

I need to have this connection settings in a .INI file and this is what I have done I modified the open event script for my main window and put this

SQLCA.DBMS=ProfileString("DB1.INI","Database","DBMS"," ")
SQLCA.DbParm=ProfileString("DB1.INI","Database","DbParm"," ")

and I created a DB1.INI file in my working directory with these lines

SQLCA.DBMS="ODBC"
SQLCA.DBParm="Connectstring='DSN=DB1'"

When I try running the app I get an error message saying
"DBMS is not supported in your current installation"

Should I have the .INI file at the root of my application folder(not powerbuilder's folder, but the application I am writting)?

Any help is appreciated.

Thanks
 
I prefer to use the DSN-less connection. Do it like this:
//DSN-less connection to a MSAccess database

string lsDataBase //connect string is assembled in this variable
string lsDBName //actual name of the .mdb to connect to. NOTE, this may be a full
//path and include network node names or mapped drive letters
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False //or TRUE as needed


//NOTE: in the following, pay very careful attention to the use of the double and single
// quote characters.

lsDataBase = "ConnectString='Provider=MSDASQL;"

lsDataBase = lsDataBase + "DBQ=" + lsDBName";"
lsDataBase = lsDataBase + "DRIVER={Microsoft Access Driver (*.mdb)};"

//if you need a userid/password for your DB, these would go between the
//double quote characters after UID and PWD or you could store the info
//in strings and substite the strings in the following
sqlca.DbParm=lsDataBase + "UID=" + "" + ";PWD=" + "" + "'"

SQLCA.DbParm = lsDataBase

CONNECT using sqlca;

IF (sqlca.sqlcode) <> 0 THEN
MessageBox(&quot;LOG ON ERROR&quot;,&quot;Failed to Connect to Database&quot;&
+string(sqlca.sqlcode)+&quot; &quot;+sqlca.DBparm&
+sqlca.sqlerrtext)
END IF


For further info, try a Google search for DSN less connection
 
Thanks for the response, but I need to be able to set my variables in an INI file so that it can be modified on the fly and I do not have to recompile the project everytime I change a database name or something like that.

Thanks again
 
You can use ProfileString() to read the value for lsDBName from an .ini file. See PB Help for details.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top