Wednesday, April 29, 2009

The connection name 'LocalSqlServer' was not found...

The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.

Thursday, April 23, 2009

MSSQL : Log file Increasing size Issue

Many developers might have faced the problem the

* Rapid growth of log file.
* Uncontrolled size of .ldf file

The first approach to analyze the exact usage of log file is to see the percentage of usage of log file.

* The size of log will grow due to many reasons like
* Temporary tables were not delete...automatically it will take time
* Due to transactions, a well managed ACID transactions should have to be used.


                 " DBCC SQLPERF(LOGSPACE) "


Other related links:
2. 

Tuesday, April 21, 2009

Distinct from Datatable Asp.net

Developers might have come across a situation where there is need to get the distinct
result of a column from a DataTable.

The possible approach
1. Traditional.. putting for loop and storing the unique in an array and searching new item whose value is not in saved array...
It is tedious,slow performance and buggy one.

2. Simple using a Dataview and datatable
// dv is a dataview
DataTable dt = dv.ToTable(true, "Columnname");


3. To be use in .Net3.5 LINQ

DataTable dtnew= dt.AsEnumerable().Distinct().CopyToDataTable();

Wednesday, April 15, 2009

Sequence contains more than one element : SingleOrDefault()

Linq

The type 'string' must be a non-nullable value type in order...

The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Null


I faced the problem when in db the columna is nullable but in application i used to face this message.

so Linq.designer.cs

for [Column(Storage="_UserID", DbType="Int NOT NULL")]
I changed it to
[Column(Storage="_UserID", DbType="Int NULL")]

My problem got fixed.


Happy coding!!

VS 2008 Intellisense is broken, not working, deactivated


Causes:
1. Due to uninstallation of ReSharper or other third party software deactivates /partial deactivates the VS 2008 intellisense .

Solution :
simple way is to follow this :
go to
Tools > Options > Text Editor > C# > General and check "Auto list members" and "Parameter information" checkboxes.

Linq : The null value cannot be assigned to a member with type System.Char which is a non-nullable value type

Monday, April 13, 2009

Error 1 Invalid token 'void' in class, struct, or interface member declaration



Solution:
May the webconfig is for 2.0, please create a dummy web site in 3.5 version and
copy all the files from current application to new one and do not overwrite the web.config, update web.config with the custom (one you have in 2.0) in it.

Sunday, April 12, 2009

allowDefinition='MachineToApplication'

It is an error to use a section registered as allowDefinition='MachineToApplication'


It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. c:\inetpub\wwwroot\Solution\Folder\web.Config


Solution:
If you are using more than two web.config try to avoid
"defaultProvider= ... " attribute or section in the child web.config.

Tuesday, April 7, 2009

enableEventValidation=”true” Problem...

pages enableEventValidation=”true” Page EnableEventValidation=”true” Problem

Invalid postback or callback argument. Event validation is enabled using > pages enableEventValidation=”true”> in configuration or < %@ Page EnableEventValidation=”true” %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.





Reasons:

* You have another <form /> tag inside your main Form tag
* Your AJAX/Javascript code changed the value of a server control
* You type tags that resemble HTML tags inside a textbox/text-area

Possible Solutions:
* check closing of "<" and "/>" tags properly in the html
* should not repeat the form tags in a single page.
* do not enter any text having html tags in the application.


Dynamic data in Web site : Step by step tutor





As most of the Asp.net developers know about Dynamic data as
Microsoft:
"ASP.NET Dynamic Data lets you create data-driven Web applications easily. It does this by automatically discovering the LINQ-to-SQL or Entities Framework data model at run time and determining how to render UI from the data model. "


Wikipedia:
"ASP.NET Dynamic Data is a Ruby on Rails inspired web application scaffolding framework from Microsoft, shipped as an extension to ASP.NET, that can be used to build data driven web applications. It exposes tables in a database by encoding it in the URI of the ASP.NET web service, and the data in the table is automatically rendered to HTML. The process of rendering can be controlled using custom design templates. Internally, it discovers the database schema by using the database metadata.
ASP.NET Dynamic Data was originally shipped as part of the "ASP.NET 3.5 Extensions" package in 2007, and was incorporated into the .NET Framework 3.5 Service Pack 1, which was released August 11, 2008."


Assumptions:
* User have .Net 3.5 and .Net 3.5 SP1 installed.
* User is aware of basic LINQ as well as Dynamic data usages.

Now let us start to put the Dynamic data into a web application and how to give the
access of data manipulation automatically to the "Admin/root".
Follow these steps.

1. Create a default Dynamic data application using VS2008 and create Linq to SQL and build the Context in it.
2. Now create a new Web application.
3. Copy the site.css, siteMaster.aspx,sitemaster.aspx.cs, Global.asax and App_code folder and DynamicData folder to the web application.
(default page is optional, but to keep it simple copy default page too).

Note: After this we need to make changes in the below following places.
a. Global.asax
b. Webapplication >> web.config.
c. DynamicData >> web.config

Changes in Global.asax
4. Need to register the context in global.asax
model.RegisterContext(typeof(AdminDataContext), new ContextConfiguration() { ScaffoldAllTables = true });
here "AdminDataContext" is the context in this sample.
5. Web application : web.config
a. In <compilation>, need to add these following assembly reference
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.ComponentModel.DataAnnotations, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
b.In <Pages> secion

< pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.DynamicData" assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>

c. In httpModules section

<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>


6. In DynamicData /Web.config
<connectionStrings>
<clear />
<add name="MembershipConnectionString" connectionString="Data Source=SCEPTER;Initial Catalog=Membership;User Id=sa;password=saimltd123"
providerName="System.Data.SqlClient" />
</connectionStrings>

Optional: To allow only users having Roles of "Administrator" or user can customize as per their requirements.
<authorization>
<allow roles="Administrator" />
<deny users="*" />
</authorization>



Running the application, will open the default.aspx and will look like this.





Happy coding...!!




Dynamic data : There is no accesible tables. Make sure that.....





Cause:
in default.aspx
System.Collections.IList visibleTables = MetaModel.Default.VisibleTables;
where MetaModel.Default.VisibleTables = 0;

Solution:
1.
In Global.asax
model.RegisterContext(typeof(AdminDataContext), new ContextConfiguration() { ScaffoldAllTables = true });

where AdminDataContext= your application db context.

2. Follow this step by step to put Dynamic data into website for easy control


Monday, April 6, 2009

Unauthorized: Logon failed due to server configuration. Asp.net



Followed:
1. In website properties.. unchecking Anonymouse authentication and checked integrated authentication.


Still no luck.

Friday, April 3, 2009

Find Post back Control ID

Find Post back Control in the Asp.net Page c#

This is a simple code to retrive the control id to identify which control is causing the postback.

Infact from
* Page.Request.Params["__EVENTTARGET"] and
* Page.Request.Params["__EVENTARGUMENT"] we can identify the arguments too.




public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
Response.Write(getPostBackControlName());
}






private string getPostBackControlName()
{
Control control = null;
//first we will check the "__EVENTTARGET" because if post back made by the controls
//which used "_doPostBack" function also available in Request.Form collection.
string ctrlname = Page.Request.Params["__EVENTTARGET"];
if (ctrlname != null && ctrlname != String.Empty)
{
control = Page.FindControl(ctrlname);
}
// if __EVENTTARGET is null, the control is a button type and we need to
// iterate over the form collection to find it
else
{
string ctrlStr = String.Empty;
Control c = null;
foreach (string ctl in Page.Request.Form)
{
//handle ImageButton they having an additional "quasi-property" in their Id which identifies
//mouse x and y coordinates
if (ctl.EndsWith(".x") || ctl.EndsWith(".y"))
{
ctrlStr = ctl.Substring(0, ctl.Length - 2);
c = Page.FindControl(ctrlStr);
}
else
{
c = Page.FindControl(ctl);
}
if (c is System.Web.UI.WebControls.Button ||
c is System.Web.UI.WebControls.ImageButton)
{
control = c;
break;
}
}
}
if(control!=null)
// return control.ID; // for simple page without any masterpage.
return control.UniqueID; // where its a contentpage and if master page is there
else
return "";


}
}



Source :
http://geekswithblogs.net/mahesh/archive/2006/06/27/83264.aspx