sqlca.Database = ProfileString (ls_startupfile, "database", "database", "")
sqlca.Logid = ProfileString (ls_startupfile, "database", "logid", "")
sqlca.Logpass= ProfileString (ls_startupfile, "database", "LogPassWord", "")
sqlca.ServerName = ProfileString (ls_startupfile, "database", "Servername", "")
sqlca.UserID = ProfileString (ls_startupfile, "database", "Userid", "")
sqlca.DBPass = ProfileString (ls_startupfile, "database", "DatabasePassword", "")
sqlca.Lock = ProfileString (ls_startupfile, "database", 'Lock', '')
sqlca.DBParm = ProfileString (ls_startupfile, "database", "DBParm", "")
/* Uncomment the following for actual DB connection */
connect using sqlca
if sqlca.sqlcode <>0 then
MessageBox ("Cannot Connect to Database", sqlca.sqlerrtext)
return
end if
sqlca.autocommit = true
toolbartext=true
主要就是这几句代码、连接sql server的、在ini文件中配置数据库相关信息、如果是access也和这里差不多、数据库用名字、连接不上就改成ip
ODBC配置选择sql server后再选择相应的数据库所在服务器,输入用户名和密码后选择默数据库就行了,记下这个配置信息的名称在PB的APP应用中添加如下代码
string ls_startupfile // holds name of start-up file
ls_startupfile='report.ini'//给配置文件变量赋值INI文件
// Populate sqlca from current preference-file settings
sqlca.DBMS = ProfileString (ls_startupfile, "database", "dbms", "") //INI文件中的头[database]
sqlca.database = ProfileString (ls_startupfile, "database", "database", "")
sqlca.dbparm = ProfileString (ls_startupfile, "database", "dbparm", "")
/* Uncomment the following for actual DB connection */
connect USING SQLCA
if sqlca.sqlcode <>0 then
MessageBox ("Cannot Connect to Database", sqlca.sqlerrtext)
return
end if
// Open MDI frame window
Open (from1)
然后在程序目录下放一个INI配置文件,如report.ini
配置文件如下:
[database]
DBMS=ODBC
Database=sig
DBPARM="ConnectString='DSN=sigUID=saPWD=sa'"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)