Recently, I was working on a graduation design. It was a small system developed with powerbuilder. This system is similar to vb I learned two years ago, but it is not the same. I started to do it when I was familiar with the environment, now the system has been completed. To sum up the small problems encountered in the past few days, sometimes it is really annoying to solve them. I hope to provide some ideas for some useful friends.
Select a data source for each running system and log on to SQL Server.
Failed to connect to the database. Incorrect connection Configuration
Here, we will first introduce four connection methods.
1. Use the SNC SQLNative Client to connect to the database
Sqlca = createtransaction
SQLCA. DBMS = "snc SQL Native Client (OLE DB)" // Interface Description
SQLCA. LogId = "sa" // database administrator ID
SQLCA. LogPass = "" // Database Administrator Password
SQLCA. ServerName = "." // database server name or IP address
SQLCA. DBParm = "Database = 'techmager'" // name of the Database to be connected
Sqlca. autocommit = true // sets whether to submit automatically
Connectusing sqlca; // execute database connection
When using snc SQL Native Client to connect to the database, the Client computer needs to install the snc SQL Native Client program Driver Interface
2. Use ole db to connect to the database
SQLCA. DBMS = "ole db" // Interface Description
SQLCA. LogId = "sa" // database administrator ID
SQLCA. LogPass = "" // Database Administrator Password
SQLCA. AutoCommit = False // sets whether to submit automatically
SQLCA. DBParm = "PROVIDER = 'sqloledb', DATASOURCE = '. ', PROVIDERSTRING = 'database = techmager' "// defines the connection parameter DATASOURCE. The database server address can be a computer name or IP address, PROVIDERSTRING = 'database = techmager' indicates that the data to be connected is techmager.
Connectusing sqlca; // execute database connection
3. Use ADO. NET to connect to the database
SQLCA. DBMS = "ADO. Net" // Interface Description
SQLCA. LogId = "sa" // database administrator ID
SQLCA. LogPass = ''// Database Administrator Password
SQLCA. AutoCommit = False // sets whether to submit automatically
SQLCA. DBParm = "Namespace = 'System. data. sqlClient ', DataSource = '. ', Database = 'techmager' "// defines the connection parameter DATASOURCE, indicating the Database server address, which can be a computer name or IP address, database = 'techmager' indicates that the data to be connected is techmager.
Connectusing sqlca; // execute database connection
When you connect to a database using ADO. NET, you must install the dotNetFramework runtime environment on the client computer to connect to the database.
Iv. UseODBCConnect to database
SQLCA. DBMS = "ODBC" // Interface Description
SQLCA. SERVERNAME = "." // server name or IP address
SQLCA. AutoCommit = False // whether to submit automatically
SQLCA. DBParm = "ConnectString = 'dsn = technology; UID = sa; PWD = zab'" // Configure the server data source
Connect using sqlca; // execute database connection
Use the ODBC interface to connect to the database. The ODBC data source must be configured on the client computer.
For the ODBC connection I used, configure the ODBC data source first, and then write the connection string. But at that time, because I wrote the wrong connection string, in order to avoid errors, I suggest you copy the configured connection statement directly. You can find it here.
First, find the Database
Then, find the data source you created, right-click Properties, and in the Preview window.
On the logon page, enter the user name and password, and an error message is displayed:
This applicationneeds a script for its open event
Solution:
An entry program is required when the application is running, which is the first event to be executed during running.
Write code in application open: open (w_login)
Having used to right-click in VS and set it as a startup project, I forgot to give it a startup Entry Program, alas ..
When the system is running, an error occurs again. I thought it was because the fields written in my program were inconsistent with the database fields, which resulted in missing or invalid information. After checking them one by one, I found that it was not my fault!
Solve this problem. Change the database connection.
SQLCA. DBParm = "ConnectString = 'dsn = drivers; UID = sa; PWD = 123456 ', DisableBind = 1, StaticBind = 0, CallEscape = 'no', DelimitIdentifier = 'yes ', stripParmNames = 'Yes '"
Because the system uses the stored procedure, ODBC does not allow parameters to be included. Therefore, you must obtain the actual value of the parameter in datawindow before calling the execution procedure. Say so.