How do you specify which .sai file to use when using a DSN? If I look at the user DSNs that are created in ODBC Administrator for various .sai files, the settings all seem to be exactly the same (server, port, username, pwd and database). I took a copy of base.sai and renamed it new.sai. Inside, I changed one of the customer's name to "Test3". When I try to connect to that database, I cannot find that record (but can find others).
Ideally, I would like to create a file DSN instead, but again, don't know how to specify which .sai file is to be used.
connectionString4 = "Provider=MSDASQL;Driver={MySQL ODBC 3.51 Driver};Server=localhost;port=13540;FILEDSN=C:\\Users\\jeff\\Desktop\\new.dsn;database=simply;Uid=sysadmin;Pwd=secret";
My thought was that the connection manager would start up the appropriate one using StartClient, but it doesn't seem to be working.
---------------------------------
string saiFile = txtFile.Text.Trim();
string sajFile = saiFile.ToLower().Replace(".sai", ".saj");
string host = string.Empty;
string port = string.Empty;
bool blnServerWasRunning = false;
ConnectionManagerServiceClient cmsc = new ConnectionManagerServiceClient();
ConnectionManagerError error = ConnectionManagerError.No_Error;
string connectionString4 = "Provider=MSDASQL;Driver={MySQL ODBC 3.51 Driver};Server=localhost;port=13540;DSN=Sage50:NEW.sai;database=simply;Uid=sysadmin;Pwd=secret";
OdbcConnection connection = new OdbcConnection(connectionString4);
try
{
error = cmsc.IsServerRunning(sajFile, ref blnServerWasRunning);
if (blnServerWasRunning == false)
{
bool blnRunningNow = false;
error = cmsc.StartClient(sajFile, ref host);
error = cmsc.GetConnectionInfo(sajFile, ref host, ref port);
error = cmsc.IsServerRunning(sajFile, ref blnRunningNow);
}
#region Test code
// Check value
OdbcConnection connection2 = new OdbcConnection(connectionString4);
connection2.Open();
OdbcCommand command = connection2.CreateCommand();
command.CommandText = "SELECT lId, sName FROM tCustomr WHERE sName = ?";
command.Parameters.Add("sName", OdbcType.VarChar).Value = "Test3";
OdbcDataAdapter oda = new OdbcDataAdapter(command);
DataTable dt = new DataTable();
oda.Fill(dt);
DataRow dr = dt.Rows[0];
int lId = (int)dr[0];
string sName = (string)dr[1];
connection2.Close();
}
catch (Exception ex)
{
MessageBox.Show("An error ocurred attempting to connect to the database: " + ex.Message, "Sage 50Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
connection2.Close();
}
if (blnServerWasRunning == false)
error = cmsc.CloseDbServerByPath(sajFile, true);