Wednesday, August 12, 2009

File Permissions Problem

We were having errors trying to move a file. The source file was occasionally “Read-only” and cannot be overwritten or deleted. To avoid this problem before we used the Delete() or CopyTo() methods of the System.IO.FileInfo class.

System.IO.FileInfo fi = new System.IO.FileInfo(fileName);
fileInfo.IsReadOnly = false;

Friday, July 17, 2009

SQL Log full

Hate getting that pesky SQL Log is full error? It only takes a minute to fix. Run:
BACKUP LOG <DatabaseName> WITH TRUNCATE_ONLY

Then, right click on your database, select Tasks -> Shrink -> Database.

Then click OK and you are done.


Thanks to Pinal at: http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/

Friday, June 26, 2009

Tabs In SQL

When trying to create a tab delimited file recently, I ran into the problem that the text field I was trying to pull back as the Description column contained tabs and these were causing issues with the rest of my query. To solve this little problem, I used SQL's replace function as follows:

REPLACE(CAST(Description AS VARCHAR(7500)), CHAR(13), ' ')
This could result in some truncating if the Description is very long, but it served my purpose just fine.

Tuesday, May 26, 2009

Drop Down List Common Functions

When programming for dropdownlists on my pages, I found that there are many ways to handle reseting the values in the boxes when populating them. I have used a for loop to check each value and set the value when it was found. However, this amounted to about 5 lines of code for each dropdownlist. I wrote these functions which I place in the CommonFunctions class which I include in each of my projects.  Here is the code:


#region SetDropDownByValue
public void SetDropDownByValue(System.Web.UI.WebControls.DropDownList dbo,
     string Value)

     for (int x = 0; x < dbo.Items.Count; x++) {
          if (dbo.Items[x].Value.Equals(Value)) { dbo.SelectedIndex = x; break; }
     }
}
#endregion 
#region SetDropDownByText
public void SetDropDownByText(System.Web.UI.WebControls.DropDownList dbo,
     string Text)
{
     for (int x = 0; x < dbo.Items.Count; x++) {
          if (dbo.Items[x].Text.Equals(Text)) { dbo.SelectedIndex = x; break; } 
     }
}
 #endregion



Using these functions saves me a number of lines of code and allows me to set dropdownlists by text or value depending on what data we have.

Enjoy!