Use DBConnection.XML if it exists in the executable folder.
This commit is contained in:
parent
dd802ce319
commit
de7194e3cb
@ -58,19 +58,35 @@ namespace VEPROMS.CSLA.Library
|
|||||||
public static string ConnectionName
|
public static string ConnectionName
|
||||||
{
|
{
|
||||||
get { return Database._ConnectionName; }
|
get { return Database._ConnectionName; }
|
||||||
set { Database._ConnectionName = value; }
|
set { Database._ConnectionName = value; _VEPROMS_Connection = null; /* Reset Connection */ }
|
||||||
}
|
}
|
||||||
|
private static string _VEPROMS_Connection;
|
||||||
public static string VEPROMS_Connection
|
public static string VEPROMS_Connection
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
if (_VEPROMS_Connection != null) // Use Lazy Load
|
||||||
|
return _VEPROMS_Connection;
|
||||||
DateTime.Today.ToLongDateString();
|
DateTime.Today.ToLongDateString();
|
||||||
|
// If DBConnection.XML exists, use the connection string from DBConnection.XML
|
||||||
|
string cnOverride = System.Windows.Forms.Application.StartupPath + @"\DBConnection.XML";
|
||||||
|
if (System.IO.File.Exists(cnOverride))
|
||||||
|
{
|
||||||
|
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
|
||||||
|
xd.Load(cnOverride);
|
||||||
|
System.Xml.XmlNode xn = xd.SelectSingleNode("DBConnection/@string");
|
||||||
|
if (xn != null)
|
||||||
|
{
|
||||||
|
return _VEPROMS_Connection = xn.InnerText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Otherwise get the value from the ConfigurationManager
|
||||||
ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings[ConnectionName];
|
ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings[ConnectionName];
|
||||||
if (cs == null)
|
if (cs == null)
|
||||||
{
|
{
|
||||||
throw new ApplicationException("Database.cs Could not find connection " + ConnectionName);
|
throw new ApplicationException("Database.cs Could not find connection " + ConnectionName);
|
||||||
}
|
}
|
||||||
return cs.ConnectionString;
|
return _VEPROMS_Connection = cs.ConnectionString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static SqlConnection VEPROMS_SqlConnection
|
public static SqlConnection VEPROMS_SqlConnection
|
||||||
|
Loading…
x
Reference in New Issue
Block a user