How to create a new connection
Some tooltip text!
• 1 minute to read
• 1 minute to read
Before you write queries, first you must create a new connection. This is the basics of SuperOffice Objectified SQL.
The following example demonstrates how this is done. This is used in all other OSQL examples.
using SuperOffice.Data;
using SuperOffice.CRM.Data;
using SuperOffice.Data.SQL;
using SuperOffice;
using(SoSession newSession = SoSession.Authenticate ("SAL0", ""))
{
//Create a new connection
SoConnection con = ConnectionFactory.GetConnection ();
if(con.Equals (null))
{
MessageBox.Show ("Connection is not created");
}
else
{
MessageBox.Show ("Connection is successfully created");
}
con.Open ();
//Here you can have all your database queries
//Once all the queries are made you can close the connection
con.Close ();
}
To use OSQL, we need to import the namespaces
SuperOffice.CRM.Data
,SuperOffice.Data
, andSuperOffice.Data.SQL
. This is done with theusing
keyword.Create and authenticate a session.
Create a connection through the
GetConnection
method of theConnectionFactory
.If the connection is successfully created, the new
SoConnection
instance will be returned.Once a new connection is created, you must first open the connection before writing any queries.
After querying, you must close the connection just as you do when writing SQL queries.