Search This Blog

Monday, February 6, 2012

how can use Ternary operator

We can  replace an if(){} else {} sequence, by Ternary  operator like so:
txtname.Text = ue.name != string.Empty ? TextUtils.Prettyname(ue.name) : string.Empty;
instead of
if (ue.name != string.Empty)
{
 txtname.Text = TextUtilss.Prettyname(ue.name);
}
else
{
 txtname.Text = string.Empty;
}
<%# (Eval(Container.DataItem,"Col_3").ToString()=="")?DataBinder.Eval(Container.DataItem,"Col_2"):DataBinder.Eval(Container.DataItem,"Col_3")%>

Example:
var value = ViewState["AValue"];
MyTextbox.Text = (value != null) ? value .ToString() : String.Empty;

Change DB owner in SQL Server Database

DECLARE @old sysname, @sql varchar(1000)
 
SELECT
 
 @old = 'oldOwner_CHANGE_THIS'
 
 , @sql = '
 
 IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES
 
 WHERE
 
     QUOTENAME(TABLE_SCHEMA)+''.''+QUOTENAME(TABLE_NAME) = ''?''
 
     AND TABLE_SCHEMA = ''' + @old + '''
 
 )
 
 ALTER SCHEMA dbo TRANSFER ?'
 
EXECUTE sp_MSforeachtable @sql

Wednesday, February 1, 2012

How can increase command time out.

ExecuteNonQuery(SqlConnection conn, CommandType cmdType, string cmdText, params SqlParameter[] cmdParameters)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout =60000;PrepareCommand(cmd, conn, cmdType, cmdText, cmdParameters);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}

System.InvalidOperationExceptionOperation is not valid due to the current state of the object.

Issue:

System.InvalidOperationExceptionOperation is not valid due to the current state of the object.
System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at System.Web.HttpRequest.FillInFormCollection()
   at System.Web.HttpRequest.get_Form()
   at Rhino.Commons.LongConversationManager.LoadConversationFromRequest(Boolean& privateConversation)
   at Rhino.Commons.LongConversationManager.LoadConversation()
   at Rhino.Commons.HttpModules.UnitOfWorkApplication.UnitOfWorkApplication_BeginRequest(Object sender, EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
          
Cause:

Microsoft recently (12-29-2011) released an update to address several serious security vulnerabilities in the .NET Framework. MS11-100 was introduced just recently that handles potential DoS attacks.

Unfortunately the fix has also broken page POSTs with very large amounts of posted data (form fields). MS11-100 places a limit of 500 on postback items. The new default max introduced by the recent security update is 1000.

Adding the setting key to the web-config file overcomes this limitation, as in this example increases it to 2000.
<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="2000" />
 </appSettings>