- /// Gets the DSN (Data Source Name) for the ADO database connection.
- /// This property actually calculates the value for this DSN.
- /// @return a @c String containing the DSN.
- __property String* get_AdoDsn()
- {
- log->Debug(S"In - get_AdoDsn()");
- StringBuilder* tempDsn = new StringBuilder();
- try {
- // Construct the Dsn
- switch (DBDriver) {
- case DBDriverType::MSSql:
- tempDsn->Append(S"SERVER=");
- tempDsn->Append(DBHost);
- tempDsn->Append(S"\\\\");
- tempDsn->Append(DBServer);
- tempDsn->Append(S";DATABASE=");
- tempDsn->Append(this->DBDatabase);
- tempDsn->Append(S";");
- if(DBUseTrustedConnection) {
- // Using a trusted connection, add the switch for this
- tempDsn->Append(S"Trusted_connection=yes;");
- } else {
- // Not using a trusted connection, add username and password
- tempDsn->Append(S"User ID=");
- tempDsn->Append(DBUserName);
- tempDsn->Append(S";Password=");
- tempDsn->Append(S";");
- }
- break;
- case DBDriverType::MySql:
- case DBDriverType::Oracle:
- throw new Exception(S"");
- break;
- }
- }
- catch (Exception*)
- {
- log->Fatal(S"Unknown error occurred whilst constructing DSN");
- log->Debug(S"Out - get_AdoDsn()");
- exit(1);
- }
- // Set the value for the ODBC DSN
- adoDsn = tempDsn->ToString();
- log->Debug(S"Out - get_AdoDsn()");
- return adoDsn;
- }
- /* 用法 */
- String* dsn = appConfig->AdoDsn;
- //该片段来自于http://www.codesnippet.cn/detail/170920135944.html
来源: http://www.codesnippet.cn/detail/170920135944.html