Skip to main content

Posts

Entity Framework Code First Error-- The path is not valid. Check the directory for the database.

You may get the the path is not valid error if you are using SQL Server CE 4.0 and do not have the ASP.Net data folder (APP_Data). Connection String Make sure you create the APP_Data folder
Recent posts

Entity Framework Code First Error -- The provider did not return a ProviderManifestToken string

There are a couple of reasons for getting this error when using Code First approach in Entity Framework  Reason 1: The name of the connection string does not match the name of the Entity Framework Context. Example: The name of my EF context JobBoardContext does not match the name of the connection string which is JobBoard. Reason 2: Entity Framework was unable to make a connection to the database. Take a look at the inner exception to get more details about the exception. Check the inner details of the exception to know more details about the connection error

Adding a Linked Server in SQL Server 2008

You can do the following in order to add a linked server to another SQL Server Instance Step 1: Run the Add Linked Server Stored Procedure EXEC sp_addlinkedserver @server=N'Server1_Instance1', --Give a name to the linked server @srvproduct=N'', @provider=N'SQLNCLI', --Provider name for SQL Server @datasrc=N'Server1\Instance1'; Step 2: Add credentials to access the linked server If the linked server can be accessed via Windows Authentication this step is not required. But if you need to access is via SQL Server authentication you need to run the following procedure by replacing the text in bold appropriately. EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname= N' Server1_Instance1 ',@useself=N'False',@locallogin=NULL,@rmtuser=N' user_id ',@rmtpassword=' password ' GO Step 3: Access the linked server You can access the linked server in the following format l inked_server.database_name.schema_name.table_

Creating a Windows Task Scheduler Service

Recently, one of my friends asked me for help in creating a windows service for scheduling some tasks. He said that he could not use the task scheduler that comes with Windows as the Task Scheduler expects each task to be a stand alone executable file. All his tasks were in a single class library and it would be a lot of work to separate each task into its own executable. Also he said that that the schedule for the tasks could change from time to time and it would be nice if he could configure the tasks in an XML file. To Recap, the requirements for the windows service are 1) The tasks should be loaded from a class library 2) The schedule information for the tasks should be configurable in an XML file. We googled (binged :)) for the solution and found an excellent article by Ajit Kumar Application Scheduler Service Using C#.Net And XML to base our solution upon. We took some good points like configuring the task information from the above mentioned article. This is how we to

Limit the characters in a multi row textbox

The maxlength property to limit the number of characters does not work on a multi row text box. We have to rely on custom JavaScript to limit the MaxLength functionality. Here is a snippet that does that. function ValidateCharCount(txtBox, maxLength,controlName) { var input; var length; input = txtBox.value; length = input.length; var allowedLength = new Number(maxLength); if (length > allowedLength) { txtBox.value = txtBox.value.substring(0, allowedLength); alert(" Only " + maxLength + " characters are allowed in the field " + controlName); txtBox.focus(); } } The function above takes three parameters. The first parameter is reference to the textbox control,second parameter is the max length of characters, third one is the textbox field description. The function kicks in once the texbox loses focus, alerts the user if the character count exceeded the allowed length and then truncates the characters to the a

IF by Rudyard Kipling

I came across this beautiful poem by Rudyard Kipling which totally blew my mind away. The poem is simple to read and sums up the way one has carry himself in just a few stanzas. Here it is in its entirety. [IF] If you can keep your head when all about you Are losing theirs and blaming it on you, If you can trust yourself when all men doubt you But make allowance for their doubting too, If you can wait and not be tired by waiting, Or being lied about, don't deal in lies, Or being hated, don't give way to hating, And yet don't look too good, nor talk too wise: If you can dream--and not make dreams your master, If you can think--and not make thoughts your aim; If you can meet with Triumph and Disaster And treat those two impostors just the same; If you can bear to hear the truth you've spoken Twisted by knaves to make a trap for fools, Or watch the things you gave your life to, broken, And stoop and build 'em up with worn-out tools: If you can make one heap of all your

Debug classic ASP in Visual Studio 2008 with SP1

At work we still have some classic ASP applications. Visual Studio 2008 did not support classic ASP debugging until SP1. Once you installed VS 2008 SP1, follow these steps to debug classic ASP. 1) Enable ASP server side script debugging in IIS a. To do this, launch IIS, right click on the virtual directory of your application, and click on properties from the context menu. Select the virtual directory tab from the properties windows. Click on the Configuration button in the application settings section. b. In the application configuration window, select the debugging tab and make sure that enable ASP server-side script debugging is checked 2) From your visual studio 2008, launch the classic ASP application by pressing F5. Wait for the asp page to show up in the browser 3) Once the application is launched, go to Debug --> Attach to Process to launch the Attach to process window. In that window, click on the Show Processes for all users checkbox to show all processes. 4) In the lis

Adding custom client side validation to controls inside GridView

Some times we find it necessary to provide custom validation to controls inside a GridView. Recently I had to have a DropDownList for selecting a country inside a gridview, the country dropdownlist contains several items including an item with the text "Other". When "Other" is selected, a textbox should show up where in the user can provide the rationale for selecting "Other". Also, I had to make sure that the textbox is not left blank when "Other" is selected. To Recap Requirements: Make sure that a value is selected from the country dropdownlist. When "Other" is selected for country, show a textbox to show enter what the "Other" country is Make sure that a value is entered in the textbox when "Other" is selected First the GridView, for simplicity I'm just showing the country dropdownlist and the TextBox. Both those controls are included in a templatefield in the GridView Leaving out the databinding details. I a

Find the cause of poor performance in Sql Server

I found the following two part article by Gail Shaw on Simple-Talk really helpful in trouble shooting poorly performing queries in Sql Server. The articles talks about spotting poorly performing queries with the help of the Profiler, understand Sql Server Query plans and fine tune the peformance using proper indexes. Part 1: http://tinyurl.com/ccl6gj Part 2: http://tinyurl.com/okcuqg

Validating checkbox list in asp.net using JQuery

ASP.net does not provide in built support to validate a checkbox list. We have to rely on custom javascript to verify if at least one checkbox in the list is checked. Since we cannot add a validator to the checkbox list, I usually put a dummy textbox on the form and add a custom validator to that textbox. <asp:CheckBoxList ID="cblLostDescription" runat="server" RepeatDirection="Horizontal" TabIndex="14"> <asp:ListItem Value="L">Lost/Stolen</asp:ListItem> <asp:ListItem Value="D">Destroyed</asp:ListItem> <asp:ListItem Value="M">Damaged</asp:ListItem> <asp:ListItem Value="O">Other</asp:ListItem> </asp:CheckBoxList> <asp:CustomValidator ID="custValDescrption" runat="server" ErrorMessage="Property Description is required" Display="Dynamic" ControlToValidate="txt

Clear Validation Errors and Validation Summary messages

ASP.net built in validation does not provide us a straight forward to clear all the validation errors. This would be really helpful while resetting a form. The reset html button would simply reset the form values but will not clear the validation errors. The following javascript code snippet can be used to clear the validation error messages. Have a reset button on your form and call the following js function onclick. <input type="reset" onclick="HideValidationErrors();" /> function HideValidationErrors() { //Hide all validation errors if (window.Page_Validators) for (var vI = 0; vI < Page_Validators.length; vI++) { var vValidator = Page_Validators[vI]; vValidator.isvalid = true; ValidatorUpdateDisplay(vValidator); } //Hide all validaiton summaries if (typeof (Page_ValidationSummaries) != "undefined") { //hide the validation summaries