Selasa, 17 Juni 2014

Database is in use error while restore database from backup (SQL Server)

Sometimes you are trying to restore a sql server database and you'll get the error:
"Exclusive access could not be obtained because the database is in use."



The Solution is type the script below and run it (SQL Query) :

Before Restore Attempt
 use master  
 alter database DB_NAME set offline with rollback immediate;  

After Restore
 use master  
 alter database DB_NAME set online with rollback immediate;  

Senin, 16 Juni 2014

Error HRESULT E_FAIL has been returned from a call to a COM component (SQL Server)

When loading large files – over 100MB with  Sql Server Management Studio 2008 you might get the following error:
Error HRESULT E_FAIL has been returned from a call to a COM component.



The Solution is run CMD (Run As Administrator) then type the script below :
 sqlcmd -S [server] -U [username] -P [password] -i [path file of sql script]  

Example :
 sqlcmd -S .\MYSQLSERVER -U sa -P pass -i C:\Database\newscript.sql  

Selasa, 10 Juni 2014

HTTP Error 404.3 - Not Found in IIS 7.5

Error :
HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Screenshot of the error page

This is a common issue and happens when IIS is installed after VS or .NET framework. So you must use aspnet_regiis.exe to register version of .NET framework you are using.

The Solution is run CMD (Run As Administrator) then type the script below :

 %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir  

Kamis, 05 Juni 2014

Hide Disable CommandField ButtonField In GridView Asp.Net

In this example i'm going to explain how to Conditionally Hide Or Disable GridView CommandField Or ButtonField Programmatically In Asp.Net Using C# And VB.
Conditionally Hide or disable Gridview commandfield buttonfield in asp.net.
I'll use field such as Select,ShowEditButton and controls in TemplateField for this demo.
Northwind Databse is used to populate GridView.
Enable selection from smart tag in design mode to show SelectButton Hyperlink in Gridview.
This Linkbutton will be hidden where country name is equal to Mexico and disabled where name is Germany in any row of grid as shown above in image.
Checkbox Control placed in ItemTemplate will also be covered.



HTML Code
   1: <asp:GridView ID="GridView1" runat="server"   
   2:        DataSourceID="sqlDataSourceGridView"   
   3:        onrowdatabound="GridView1_RowDataBound"   
   4:        AutoGenerateColumns="false">  
   5: <Columns>  
   6: <asp:CommandField ShowSelectButton="True"/>  
   7:         
   8: <asp:TemplateField>  
   9: <ItemTemplate>  
  10: <asp:CheckBox ID="chkSelect" runat="server"   
  11:       Visible='<%# ShowHide(Eval("Country"))%>'/>  
  12: </ItemTemplate>  
  13: </asp:TemplateField>  
  14: <asp:BoundField DataField="CustomerID"   
  15:         HeaderText="Customer ID"/>  
  16: <asp:BoundField DataField="City" HeaderText="city"/>  
  17: <asp:BoundField DataField="Country"   
  18:         HeaderText="Country"/>  
  19: </Columns>  
  20: </asp:GridView>  
  21:           
  22: <asp:SqlDataSource ID="sqlDataSourceGridView"   
  23:           runat="server"   
  24:           ConnectionString=  
  25: "<%$ ConnectionStrings:northWindConnectionString %>"   
  26: SelectCommand="SELECT [CustomerID], [City], [Country]   
  27:         FROM [Customers]">  
  28: </asp:SqlDataSource>  


C# Code
1:  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
2:  {  
3:       if (e.Row.RowType == DataControlRowType.DataRow)  
4:       {  
5:            string country = DataBinder.Eval(e.Row.DataItem, "Country").ToString();  
6:            if (country == "Mexico")  
7:            {  
8:                 LinkButton lb = (LinkButton)e.Row.Cells[0].Controls[0];  
9:                 lb.Visible = false;  
10:            }  
11:            else if (country == "Germany")  
12:            {  
13:                 e.Row.Cells[0].Enabled = false;  
14:            }  
15:       }  
16:  }  
17:  protected bool ShowHide(object country)  
18:  {  
19:       if (country.ToString() == "France")  
20:            return false;  
21:       else  
22:            return true;  
23:  }  


VB Code
1:  Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs)  
2:       If e.Row.RowType = DataControlRowType.DataRow Then  
3:            Dim country As String = DataBinder.Eval(e.Row.DataItem, "Country").ToString()  
4:            If country = "Mexico" Then  
5:                 Dim lb As LinkButton = DirectCast(e.Row.Cells(0).Controls(0), LinkButton)  
6:                 lb.Visible = False  
7:            ElseIf country = "Germany" Then  
8:                 e.Row.Cells(0).Enabled = False  
9:            End If  
10:       End If  
11:  End Sub  
12:  Protected Function ShowHide(country As Object) As Boolean  
13:       If country.ToString() = "France" Then  
14:            Return False  
15:       Else  
16:            Return True  
17:       End If  
18:  End Function  

 
Welly Sundawa Well Blog