BusinessMgr
This commit is contained in:
@@ -17,9 +17,9 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
// Database configuration
|
||||
public class OdbcConfig
|
||||
{
|
||||
public DbmsType dbms = DbmsType.General;
|
||||
public String connectionString; // Raw connection string.
|
||||
public String location, user, pword; // Application properties.
|
||||
public DbmsType Dbms = DbmsType.General;
|
||||
public String ConnectionString; // Raw connection string.
|
||||
public String Location, User, Password; // Connection properties.
|
||||
/// <summary>Database name populated when connection string is generated if not done previously.</summary>
|
||||
public String DatabaseName { get; set; }
|
||||
}
|
||||
@@ -42,9 +42,9 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
//-------------------------------------------------------------------
|
||||
public static DbmsType GetDbmsType(OdbcConfig config)
|
||||
{
|
||||
if (config.dbms == DbmsType.MsSql || config.location.Left(6).EqualsCI("MsSql:"))
|
||||
if (config.Dbms == DbmsType.MsSql || config.Location.Left(6).EqualsCI("MsSql:"))
|
||||
return DbmsType.MsSql;
|
||||
return config.dbms;
|
||||
return config.Dbms;
|
||||
}
|
||||
public static String GenerateConnectionString(OdbcConfig config, bool dbmsSpecificConnectionString = false)
|
||||
{
|
||||
@@ -58,7 +58,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
// MsSql:Server:Port\Instance.Database
|
||||
dbms = DbmsType.MsSql;
|
||||
String sqlDriver = OdbcUtil.GetOdbcSqlDriverName();
|
||||
String sqlLocation = config.location.Left(6).EqualsCI("MsSql:") ? config.location.Substring(6) : config.location;
|
||||
String sqlLocation = config.Location.Left(6).EqualsCI("MsSql:") ? config.Location.Substring(6) : config.Location;
|
||||
String sqlServer = "."; /* Assume local host */
|
||||
String sqlInstance = "";
|
||||
String sqlPort = "";
|
||||
@@ -99,17 +99,17 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
// WsId=<WorkstationId>;
|
||||
// Server=[protocol:]Server[,port][\instancename];
|
||||
// Database=<Default database>;
|
||||
// Trusted_Connection=<Yes|No>;
|
||||
// Trusted_Connection=<Yes|No>; [or Integrated Security=SSPI;]
|
||||
// UseProcForPrepare=2
|
||||
connectionString = "Driver={" + sqlDriver + "};";
|
||||
connectionString += "Server=" + sqlServer + ";";
|
||||
connectionString += "Database=" + sqlDatabase + ";";
|
||||
if (!config.user.IsEmpty())
|
||||
if (!config.User.IsEmpty())
|
||||
{
|
||||
connectionString += "UID=" + config.user + ";";
|
||||
connectionString += "PWD=" + config.pword + ";";
|
||||
connectionString += "UID=" + config.User + ";";
|
||||
connectionString += "PWD=" + config.Password + ";";
|
||||
}
|
||||
connectionString += "Trusted_Connection=" + (config.user.IsEmpty() ? "Yes" : "No") + ";";
|
||||
connectionString += "Trusted_Connection=" + (config.User.IsEmpty() ? "Yes" : "No") + ";";
|
||||
// Mar24 Added to avoid 'The certificate chain was issued by an authority that is not trusted'.
|
||||
connectionString += "TrustServerCertificate=Yes;";
|
||||
// Multiple Active Result Sets.
|
||||
@@ -125,23 +125,23 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
connectionString = "";
|
||||
connectionString += "Server=" + sqlServer + ";";
|
||||
connectionString += "Database=" + sqlDatabase + ";";
|
||||
if (!config.user.IsEmpty())
|
||||
if (!config.User.IsEmpty())
|
||||
{
|
||||
connectionString += "User Id=" + config.user + ";";
|
||||
connectionString += "Password=" + config.pword + ";";
|
||||
connectionString += "User Id=" + config.User + ";";
|
||||
connectionString += "Password=" + config.Password + ";";
|
||||
}
|
||||
connectionString += "Trusted_Connection=" + (config.user.IsEmpty() ? "Yes" : "No") + ";";
|
||||
connectionString += "Trusted_Connection=" + (config.User.IsEmpty() ? "Yes" : "No") + ";";
|
||||
// Mar24 Added to avoid 'The certificate chain was issued by an authority that is not trusted'.
|
||||
connectionString += "TrustServerCertificate=Yes;";
|
||||
}
|
||||
|
||||
// Populate configuration values if blank.
|
||||
if (config.dbms <= 0)
|
||||
config.dbms = dbms;
|
||||
if (config.Dbms <= 0)
|
||||
config.Dbms = dbms;
|
||||
if (StringUtil.IsEmpty(config.DatabaseName))
|
||||
config.DatabaseName = sqlDatabase;
|
||||
|
||||
SaLogger.Info($"{SysUtil.Fn} Driver: " + sqlDriver + ". Server: " + sqlServer + ". Database: " + sqlDatabase + ". Connection: " + connectionString);
|
||||
//SaLogger.Debug($"{SysUtil.Fn} Driver: " + sqlDriver + ". Server: " + sqlServer + ". Database: " + sqlDatabase + ". Connection: " + connectionString);
|
||||
}
|
||||
return connectionString;
|
||||
}
|
||||
@@ -152,17 +152,17 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
public static SacsDatabase OpenOdbcDatabase(OdbcConfig config)
|
||||
{
|
||||
// Populate configuration.
|
||||
config.dbms = GetDbmsType(config);
|
||||
config.Dbms = GetDbmsType(config);
|
||||
|
||||
// Connection strings.
|
||||
String connectionString = config.connectionString;
|
||||
String connectionString = config.ConnectionString;
|
||||
if (StringUtil.IsEmpty(connectionString))
|
||||
connectionString = GenerateConnectionString(config);
|
||||
String sqlConnectionString = GenerateConnectionString(config, true);
|
||||
|
||||
// Open database.
|
||||
DbGlobalDbms.Type = config.dbms;
|
||||
SacsDatabaseOdbc database = new SacsDatabaseOdbc(config.dbms, config.DatabaseName, connectionString);
|
||||
DbGlobalDbms.Type = config.Dbms;
|
||||
SacsDatabaseOdbc database = new SacsDatabaseOdbc(config.Dbms, config.DatabaseName, connectionString);
|
||||
database.SelectLockMode = SelectLockMode.ReadUncommitted;
|
||||
database.SqlConnectionString = sqlConnectionString;
|
||||
return database;
|
||||
|
||||
Reference in New Issue
Block a user