To connect to a database you should create and use a SAConnection object.
For this tutorial we are going to connect to a local SQL Server database demo
as a user guest
with a password secret
and then disconnect from it.
Connect to Database
The code below creates a connection object con
represented by SAConnection class:
SAConnection con;
con.Connect(_TSA("demo"), _TSA("guest"), _TSA("secret"), SA_SQLServer_Client);
Remote Connection and Authentication
Choose your server for additional info
If you want to define the connection con
as a connection to SQL Server database before calling SAConnection::Connect method use SAConnection::setClient method:
SAConnection con;
con.setClient( SA_SQLServer_Client );
con.Connect(_TSA("demo"), _TSA("guest"), _TSA("secret"));
Disconnect from Database
You can disconnect your connection object at any time with a call to the SAConnection::Disconnect method:
con.Disconnect();
It is safe to skip calling SAConnection::Disconnect method explicitly. Destructor SAConnection::~SAConnection will correctly close the connection if you didn't call SAConnection::Disconnect method before.