SQL Server 20XX : Unable to modify table…

After 3+ years of not touching SQL Server, I managed to get my hands on SQL Server 2012.  After creating two tables, and deciding to modify the first table schema, I get my first error message….

“Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created….yada..yada…yada.”

So, sound coding methodologies suggest we analyze the change properly, and use caution while doing this. However, if you are starting off with a new project, there is always an option in the tools menu.

Tools > Options > Designers > Uncheck “Prevent saving changes that require table re-creation

image

Including script files in masterpages (ASP.NET)

One of the issues I have faced with including site-wide JS files while developing web-applications is the simple fact that I was developing in Windows XP and IIS 5. And IIS puts in each of my websites as virtual-directories. So , I always have trouble including references to js files from the master-pages.

One alternative was to have a virtual directory outside the project structure and point it to the js folder, and my references would work properly. But there are other nicer ways to do the same.

1. Include the script tag as a server side tag, and give the reference to the file with a “~”

 <script language="javascript" src="~/App_Common/Scripts/tablecloth.js" runat="server"></script>

2. Add some code to your masterpage’s load event that would register the file after resolving the client url.

 protected void Page_Load(object sender, EventArgs e) { this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "tableCloth", this.ResolveClientUrl("~/App_Common/Scripts/tablecloth.js")); } 

The above two approaches completely avoid having to create a virtual directory of any kind, and work all the time … so long as the path is correct.

[HowTo] Generate a dummy table for binding to a tabular structure.

While designing grids and related styles, I always found the need to bind some dummy data to the grid to see how the grid looks. So, rather than making a database call to get a really organized table, I decided to get one of my own.

The following method generates and returns a data-table to be bound to any tabular structure.

 1: public DataTable GetDummyData(int columnCount, int rowCount, bool useNumeric, int rowLength, int minNumber, int maxNumber)
 2: {
 3: DataTable dt = new DataTable();
 4: dt.Columns.Add(new DataColumn(" ", typeof(string)));
 5:  
 6: for (int c = 0; c < columnCount; c++)
 7: {
 8: string columnName = RandomString(rowLength, false);
 9: if (useNumeric == true)
 10: {
 11: dt.Columns.Add(new DataColumn(columnName, typeof(Int32)));
 12: }
 13: else
 14: {
 15: dt.Columns.Add(new DataColumn(columnName, typeof(string)));
 16: }
 17: }
 18: for (int j = 1; j <= rowCount; j++)
 19: {
 20: DataRow dr = dt.NewRow();
 21: dr[0] = RandomString(4, false);
 22: for (int k = 1; k <= columnCount; k++)
 23: {
 24: if (useNumeric == true)
 25: {
 26: dr[k] = RandomNumber(minNumber, maxNumber);
 27: }
 28: else
 29: {
 30: dr[k] = RandomString(rowLength, true);
 31: }
 32: }
 33: dt.Rows.Add(dr);
 34: }

      
 35: return dt;
 36: }

Disclaimer : Don’t use it for production. This is just to test on your local machines.