Sunday, October 25, 2015

Create a New SQL Server Database basing from a renamed DB (mdf/ldf) files

I recently created a copy of Northwind database and called it NorthwindBootstrap. This database has a built-in membership tables added to it. The copy includes both of mdf and ldf files. My next step is to create a new database based from the recently copied/renamed files in which I have no idea on how to do it.
After doing some research, I stumbled upon a t-sql script based from my requirement.
 USE [master]  
 GO  
 CREATE DATABASE [NorthwindBootstrap] ON   
 ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\NorthwindBootstrap.mdf' ),  
 ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\NorthwindBootstrap.ldf' )  
 FOR ATTACH  
 GO  

Cheers! :)

Wednesday, October 21, 2015

The specified cast from a materialized 'System.Int16' type to a nullable 'System.Int32' type is not valid.

Based from the issue, the fix is to check the database field against the view model class. In my case, the database field is smallint (nullable).
So, the fix is to change the model code from:
 public int? StockOnHand { get; set; }  
to:
 public Int16? UnitsInStock { get; set; }  
:-)

Tuesday, October 20, 2015

Draggable is not a function in ASP.NET MVC

Here's what I did in order to recognize the draggable function in one of my asp.net mvc page.
1. Add jquery-ui.js to scripts folder.
2. Bundle the js file in BundleConfig.cs
3. Render the bundled script in _Layout.cshtml.


Cheers! :-)

Check if images are not rendered correctly to the browser using JavaScript

Hello,
Here's a function to hide divs if it's children specifically images does not render correctly to the browser or an error has occured.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
function ImageDivHandler() {    
   $("div.gallery").each(function () {  
     if ($(this).children().length == 0) {  
       $(this).hide();  
     }  
     else {  
       var img = $(this).find(".image-responsive");  
       if (img != null || img != undefined) {  
         imgSrc = $(this).find(".image-responsive").attr("src");  
         if (imgSrc == "" || imgSrc == null || imgSrc == "null") {  
           $(this).find(".image-responsive").closest("div.gallery").hide();  
         }  
         else {  
           $(this).find(".image-responsive").error(function () {  
             $(this).closest("div.gallery").hide();  
           });  
         }  
       }  
     }  
   });  
 }  
Note: I may change the logic from time to time depending on the layout of the image container. But the concept is pretty much the same.
Greg

Sunday, October 18, 2015

jQuery Intellisense not working in external Javascript file using Visual Studio 2013

Hello,

In order for the jQuery intellisense to work in Visual Studio 2013, perform the following steps.
1. Proceed by clicking Tools -> Options -> Text Editor -> JavaScript -> Intellisense -> References.
2. Change Reference Group to Implicit (Web)
  By default a reference has been added to _references.js. If not, add a new reference file under Scripts folder.
3. Open _references.js file using your Visual Studio IDE or any text editor software.
4. Add reference path to jquery files (.js, .min.js, and .intellisense.js).

5. Close Visual Studio and Open it again. (I was struggling for hours as to why performing steps 1 through 4 didn't work. This step fixed the issue)

Reference: jQuery intellisense not working in VS 2012
Regards,
:)