// TODO: MULTI: decision on what db to use can be used here and only here. /// <summary> /// Initializes this object instance by creating an instance of the Internal SqlConnection object. /// </summary> /// <param name="Database" >The Associated Database Name that this Data Service instance will be communicating with</param> /// <value>void</value> private void ConstructMe(TDatabase db, string DBName, string ServerName) { byte minConnect; byte maxConnect; //this call will do lots of cool things, but will give us back the name of the server that the caller needs. //it will also change the DBName if it is mapped to another actual name mDatabaseName = (db == TDatabase.Unknown ? DBName : db.ToString()); mDatabase = db; if (ServerName != null) msDatabaseServer = ServerName; else msDatabaseServer = DBLocator.getDatabaseServer(ref mDatabaseName); DBLocator.getConnectionPoolMinMax(mDatabaseName, out minConnect, out maxConnect); try { msActiveConnectionString = "Application Name=" + this.ApplicationName + ";" + "server=" + msDatabaseServer + ";" + "trusted_Connection=yes;" + "Database=" + mDatabaseName + ";" + "connection reset=false;" + "enlist=true;" + "min pool size=" + minConnect + ";" + "max pool size=" + maxConnect; msActiveConnectionString = FixConnectionString(msActiveConnectionString); moDBConn = new SqlConnection(msActiveConnectionString); } catch (Exception ex) { //Lets Use The MS Application Block here w/a custom publisher that sends out an eMail & Publishes exception data to a structure in the Shared Database. //If Shared DB is not available then publish exception data to the event log. throw new Exception(ex.Message, ex); } }
public SqlUtil(TDatabase Database, string appName) : this(Database, Database.ToString(), appName) { }
public static SqlUtil Get(TDatabase Database, string appName) { bool NoCaching = true; if (NoCaching) { return new SqlUtil(Database, appName); } //save a copy of original for later use, in case first call to getDatabaseServer modifies it string db = Database.ToString(); string svr = DBLocator.getDatabaseServer(ref db); string k = string.Format("{0}:{1}:{2}", Process.GetCurrentProcess().Id, svr, db); lock (xDBLock) { if (mRegisteredConnection[k] == null) { mRegisteredConnection[k] = new SqlUtil(Database, appName); } return (SqlUtil)mRegisteredConnection[k]; } }
/// <summary> /// Returns a fully qualified path to the specified table. /// </summary> /// <param name="LogicalDBName"></param> /// <param name="tableName"></param> /// <returns></returns> public static string getTablePath(TDatabase db, string tableName) { string ActualDBName = db.ToString(); string dbServer = getDatabaseServer(ref ActualDBName); if (tableName.Substring(0, 1) != "[") tableName = "[" + tableName + "]"; if (dbServer.Substring(0, 1) != "[") dbServer = "[" + dbServer + "]"; return string.Format("{0}.{1}.dbo.{2}", dbServer, ActualDBName, tableName); }