Through the SalesLogix .Net extensions a SLX Application wrapper is provided to the extension. Access into the core functionality is very possible including calling the GetNewConnection() method. I actually believe that this is a bad thing and see no reason why this is here. Some of my reasons;
- This method call returns back an unmanaged ADO connection (not ado.net)
- There is a property exposed that provides the actual connection string ISlxApplication.ConnectionString
- Using the connectionstring paired with the OleDb database objects is the correct way to go in writing code that is in the .net extensions that needs database access
- Is the right thing to do
My feeling is there is still a lot of developers out there that understand SalesLogix scripting very well but not .Net and how to write well partitioned code.
So in a nut shell … in your code do the following;
private string _connectionString;
void IRunnable.Initialize(ISlxApplication SlxApplication, ILicenseKeyManager LicenseKeyManager)
{
_connectionString = SlxApplication.ConnectionString;
}
object IRunnable.Run(object[] Args)
{
using (OleDbConnection conn = new OleDbConnection(_connectionString))
{
conn.Open();
using (OleDbCommand command = conn.CreateCommand())
{
command.CommandText = “Select count(*) from Account”;
int count = (int)command.ExecuteScalar();
}
}
}
– Mark