# Thursday, June 21, 2007
« The Empire | Main | New Computer Joy »

How not to handle storing database connection string information

// if we don't find the connection string in session state, assume that we
// need to initialize all session variables
if (this.Session["connect_comersus"] == null)
{
    this.Session.Add("connect_comersus", (string) strConnect);
}

How not to get the current assembly version for a web app, here's the relevant appSetting:

<add key="dll_path" value="\\CorpWebServer\WebAppROOT$\Secure\bin\Company.CorpSite.Secure.dll" />

Here's the code that reads the version:

        private string GetBuildText()
        {
            string strPath = null,
                strVersion = null,
                strDate = null,
                strReturn = null;
            FileInfo fiMain = null;
            Assembly objMain = null;

            strPath = ConfigurationSettings.AppSettings["dll_path"];
            fiMain = new FileInfo(strPath);
            if (fiMain.Exists)
            {
                objMain = Assembly.LoadFrom(strPath);

                strDate = fiMain.LastWriteTime.ToString("ddMMMyyy HH:mm");
                strVersion = objMain.GetName().Version.ToString();

                strReturn = strVersion + " &diams; " + strDate;
            }
            else strReturn = String.Empty;

            return strReturn;
        }

There are many more, but that's enough for right now.




WTF
Comments are closed.