Thursday, May 28, 2009

SQL Server 2005: Importing from Excel error 0xc020901c

Error 0xc020901c: Data Flow Task: There was an error with output column "Agenda 2" (63) on output "Excel Source Output" (9). The column status returned was: "Text was truncated or one or more characters had no match in the target code page.".


To fix the problem

  • To change the value of TypeGuessRows, use these steps:
  • On the Start menu, click Run. In the Run dialog box, type Regedt32, and then click OK.
  • Open the following key in the Registry editor:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel
  • Double-click TypeGuessRows.
  • In the DWORD editor dialog box, click Decimal under Base. Type a value between 0 
  • Click OK, and then exit the Registry Editor.

http://support.microsoft.com/kb/281517/EN-US/

Wednesday, May 13, 2009

How to Close Web Browsers

btn.Attributes.Add("OnClick", "self.close()");
will do the trick.
Another alternative is
Response.Write (" < script > self.close() ; < /script >
");

Wednesday, April 22, 2009

DataBase could not be exclusively Locked when renaming a database

The problem is due to other users using the database. To resolve the problem, you set the database to be used only by yourself. After the rename operation, you need to reset it back to be usable by other users. It is a common courtesy to inform all users prior to doing this operation.

ALTER DATABASE DBNAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
SP_RENAMEDB @dbname = 'old_name' ,
@newname = 'new_name'
Go
ALTER DATABASE NEWDBNAME SET MULTI_USER -- set back to multi user
GO

Monday, March 16, 2009

How to Sort or handle Paging in GridView Manually without databinding

The GridView 'GridViewID' fired event PageIndexChanging which wasn't handled.
The GridView 'GridViewID' fired event Sorting which wasn't handled.

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;

switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GridViewSortExpression = e.SortExpression;
int pageIndex = this.GridView1.PageIndex;
this.GridView1.DataSource = SortDataTable(GridView1.DataSource as DataTable, false);
this.GridView1.DataBind();
this.GridView1.PageIndex = pageIndex;

}

private string GridViewSortDirection
{
get
{
return ViewState["SortDirection"] as string ?? "ASC";
}

set
{
ViewState["SortDirection"] = value;
}
}



private string GridViewSortExpression
{
get
{
return ViewState["SortExpression"] as string ?? string.Empty;
}
set
{
ViewState["SortExpression"] = value;
}
}



private string GetSortDirection()
{
switch (GridViewSortDirection)
{
case "ASC":
GridViewSortDirection = "DESC";
break;
case "DESC":
GridViewSortDirection = "ASC";
break;
}
return GridViewSortDirection;
}



protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.DataSource = SortDataTable(this.GridView1.DataSource as DataTable, true);
this.GridView1.PageIndex = e.NewPageIndex;
this.GridView1.DataBind();
}

protected DataView SortDataTable(DataTable dataTable, bool isPageIndexChanging)
{
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
if (GridViewSortExpression != string.Empty)
{
if (isPageIndexChanging)
{
dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection);
}
else
{
dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GetSortDirection());
}
}
return dataView;
}

else
{
return new DataView();
}
}

How to have Display Number in GridView

< asp:TemplateField >
< ItemTemplate >
< %# Container.DataItemIndex + 1 % >
< /ItemTemplate >
< /asp:TemplateField >

Tuesday, March 10, 2009

Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started..

The error that you are getting is because your StateServer is not enabled. You have to go to AdministrativeTools > Computer Management > Services and Applications >Services and start the ASP.NET State Service

The SQL Server Service Broker for the current database is not enabled, and as a result query notifications are not supported...

This problem frequently occurs when you just restored a database, but service brokers are broken or lost.

To resolve this problem.

alter database xxxx set NEW_BROKER

Alternatively,

1. Go to Programs -> Microsoft Sql Server 2005 -> Configuration Tools -> Sql Server Surface Area Configuration -> Surface Area Configuration for Features.
2. Locate "Service Broker" under the database engine and enable it.

Sunday, March 08, 2009