Home > Back-end >  Adotable SQL database connection appear missing connection string error
Adotable SQL database connection appear missing connection string error

Time:10-14

I use the connectionstring property of Adotable wrote a piece of code, intention and SQL database connection is established, through it a missing connectiong or error of the connectionstring, preliminary suspect is an error in the variable type, the code is as follows:
Infile2. Open (".. \ \ data_dd \ \ config. TXT ");
Getline (infile2 config);
Infile2. Close ();
ADOTable2 - & gt; The ConnectionString=config. C_str ();
ADOTable2 - & gt; TableName=tablename2;
ADOTable2 - & gt; Active=true;
The config is of type string variables;
In the config. TXT is a string of characters (the contents of the quotes) :
"The Provider=SQLOLEDB. 1; Password=wq2mds; Persist Security Info=True; User ID=wq2mds; Initial Catalog=WQ2MDS; Data Source=192.168.1.103 ";
(my intention is to mainly in the user name and password, and IP change under the condition of program can run, so will ADOTable2 - & gt; ConnectionString assignment with a variable instead of, so that the user name, password and IP changed, just in a text file "config. TXT" operation is ok)
Masters who can tell you...

CodePudding user response:

ADOTable2 - & gt; The ConnectionString=config. C_str ();
In this line of code used to add:
ShowMessage (config);

See from the file read into the connection string is correct,

CodePudding user response:

The config. C_str () on the designer to try to see the right,

CodePudding user response:

The designer of what, really do not understand...

CodePudding user response:

The designer is to see the attributes of the object that panel

CodePudding user response:

With a ADOConnection first connect to the database, and then use ADOQUERY ADOTABLE or even to ADOConnection
AnsiString sPath=ExtractFilePath (Application - & gt; ExeName);
TStringList * sl=new TStringList ();
Sl - & gt; LoadFromFile (sPath + "config. TXT");
ADOConnection - & gt; The ConnectionString=sl - & gt; Strings [0].
Try {
ADOConnection - & gt; Connected=true;
} the catch (Exception & amp; E) {
ShowMessage (" connect to database failure! Reason: "+ e.M essage);
The delete sl;
Application - & gt; The Terminate ();
}
The delete sl;
ADOTable2 - & gt; The Connection=ADOConnection;
ADOTable2 - & gt; TableName=tablename2;
ADOTable2 - & gt; Active=true;

CodePudding user response:

Take a look at your connection string if there is a problem
  • Related