Uncategorized

clear previous history in every textbox

Its a problem recently I am facing in my recent project.

So my client told me you should clear previous history in every textbox. So I just write a textbox properties in Page_Prerender event in my page(codebehind).
protected void Page_PreRender(Object sender, EventArgs e)
{
txtPassword.Attributes.Add(“autocomplete”, “off”)
txtConfirmPassword.Attributes.Add(“autocomplete”, “off”);
}

It will solve your problem.

Dynamically Add Header in Crystal Report

string amount = amountTextBox.Text;
string titleString = ” Total Sanctions above “;

List investmentList = new List();
investmentList = new InvestmentManager().CollectAmountWiseInvestment(amount);

expirySanctionCrystalReport reportDocumentObject = new expirySanctionCrystalReport();

//Set Crystal Report Header
CrystalDecisions.CrystalReports.Engine.TextObject amountText = (CrystalDecisions.CrystalReports.Engine.TextObject)reportDocumentObject.ReportDefinition.ReportObjects[“dateText”];
amountText.Text = amount;

CrystalDecisions.CrystalReports.Engine.TextObject titleText = (CrystalDecisions.CrystalReports.Engine.TextObject)reportDocumentObject.ReportDefinition.ReportObjects[“TextTitle”];
titleText.Text = titleString;

reportDocumentObject.SetDataSource(investmentList);
amountWiseCrystalReportViewer.ReportSource = reportDocumentObject;
amountWiseCrystalReportViewer.RefreshReport();
amountWiseCrystalReportViewer.Visible = true;

Get Last Day Of Month

—-Last Day of Previous Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
LastDay_PreviousMonth
—-Last Day of Current Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
LastDay_CurrentMonth
—-Last Day of Next Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))
LastDay_NextMonth
ResultSet:
LastDay_PreviousMonth
———————–
2007-07-31 23:59:59.000

LastDay_CurrentMonth
———————–
2007-08-31 23:59:59.000

LastDay_NextMonth
———————–
2007-09-30 23:59:59.000

If you want to find last day of month of any day specified use following script.
–Last Day of Any Month and Year
DECLARE @dtDate DATETIME
SET @dtDate = ‘8/18/2007’
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@dtDate)+1,0))
LastDay_AnyMonth
ResultSet:
LastDay_AnyMonth
———————–

Email From SQL in HTML format

declare @body1 nvarchar(MAX)
set @body1 = N’

:: Report(1-06-2011 To 30-06-2011) ::

‘ +
N’

‘ +
N” + CAST ( ( SELECT
td = FirstName, ”,
td = LastName, ”,
td = EmailId, ”
from Users
ORDER BY FirstName ASC FOR XML PATH(‘tr’), TYPE ) AS NVARCHAR(MAX) ) +
N’

First Name Last Name Email


print @body1
EXEC msdb.dbo.sp_send_dbmail @recipients=’sunil@iglobeconsulting.com’,
@subject = ‘My Mail Test’,
@body = @body1,
@profile_name = ‘Prakash Rathod’,
@body_format = ‘HTML’ ;

Use Uniqueidentifier in dynamic SQL in SQL Server 2008/2005

We used to use uniqueidentifier so many times in our database, since it is one of the unique field in table, we may need to put it in dynamic SQL quite a few times but I have seen so many times that even seasoned developer don’t know how to use UniqueIdentifier in dynamic SQL, may be in Store procedure in SQL Server. This is the reason I tempted to write something for this topic.

Let us see it practically:

–create table for testing
if OBJECT_ID(‘IDTester’) is not null drop table IDTester
create table IDTester
(
ID uniqueidentifier default newid(),
name varchar(20)
)
GO

–insert few records
insert into IDTester(name)
select ‘Ritesh’ union all
select ‘Rajan’ union all
select ‘Bihag’ union all
select ‘Abhijit’
GO

–let us see what we come up with
select * from IDTester
GO

–create simple SP
Create proc SPIDTester
@ID uniqueidentifier
as
begin
select * from IDTester where ID=@ID
end
GO

—-I got ‘7F1D8BC8-48AA-437E-B19F-4ABD139AD5E5’ for first record
—-you may get something else as a ID of first records.
exec spidtester ‘7F1D8BC8-48AA-437E-B19F-4ABD139AD5E5′
GO

–let us create another SP with dynamic SQL but it will show us an error
Create proc SPIDTester2
@ID uniqueidentifier
as
begin
declare @sql varchar(max)
set @sql=’select * from IDTester where ID=’ + @ID
exec (@sql)
end
GO
–if you will try to create above SP, you will be greeted with
–following error
–Msg 402, Level 16, State 1, Procedure SPIDTester2, Line 6
–The data types varchar and uniqueidentifier are incompatible in the add operator.

–you have to use sp_executeSQL to get rid of above error
–with additional parameter
create proc SPIDTester2
@ID uniqueidentifier
as
begin
declare @sql nvarchar(max)
set @sql=’select * from IDTester where ID=@I’
exec sp_executesql @sql,N’@I uniqueidentifier’,@I=@ID
end
GO

–let us see whether SP actually works
exec spidtester2 ‘7F1D8BC8-48AA-437E-B19F-4ABD139AD5E5′
GO

———————————– Pass more then one parameter —————————————-

DECLARE @SQL_String NVARCHAR(max)
DECLARE @Parameter_Definition NVARCHAR(max)

SET @SQL_String = N’
EXEC GetEmail2 @EmployeeId = @EmployeeId_input, @Email = @Email_out OUTPUT

SET @Parameter_Definition = N’
@EmployeeId_input uniqueidentifier,
@Email_out nvarchar(50) OUTPUT’

DECLARE @EmployeeId uniqueidentifier
DECLARE @Email nvarchar(50)

SET @EmployeeId = ‘997B3351-F876-414B-9C63-B90EC967B69B’

EXECUTE sp_executesql @SQL_String, @Parameter_Definition, @EmployeeId_input = @EmployeeId, @Email_out = @Email OUTPUT

SELECT @Email as Email

GO

Super Impose Image

Refere Link: http://www.codeproject.com/KB/GDI-plus/watermark.aspx

Download code: https://skydrive.live.com/?cid=efc0ec2e2cd761ee#!/?cid=efc0ec2e2cd761ee&id=EFC0EC2E2CD761EE%21150

impose one image on another image. it’s also called watermark effect also.

Textbox should not contain special character using JavaScript

Call Javascript function on “onkeyup” event of TextBox




function valid(field) {
var txt = document.getElementById(‘TextBox1′).value;
var iChars = “!@$%^&*()+=-[]\\\’;,./{}|\”:?~_”;
for (var i = 0; i < txt.length; i++) {
if (iChars.indexOf(txt.charAt(i)) != -1) {
alert(“Your string has special characters. \nThese are not allowed.”);
document.getElementById(‘TextBox1′).value = txt.substring(0, txt.length – 1);
return false;
    }
  }
}

function isSpclChar(){
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":?";
for (var i = 0; i < document.qfrm.q.value.length; i++) {
    if (iChars.indexOf(document.qfrm.q.value.charAt(i)) != -1) {
    alert ("The box has special characters. \nThese are not allowed.\n");
    return false;
        }
    }
}   

Windows 7 couldn’t connect to work group server

Browse to “Local Policies” -> “Security Options”. Now look for the entry “Network Security: LAN Manager authentication level” and open it. Click on the dropdown menu and select “Send LM & NTLM – use NTLMv2 session security if negotiated”. Apply the settings.

In the Advanced sharing settings page of Network and sharing center, you need to have it set as Work/Home profile. Try

-Enable network discovery
-Turn on file and print sharing
-Turn off password protected sharing
-Use user accounts and passwords to connect to other computers

The other settings such as encryption I have set as use 128 bit encryption.

Please check related policies.

1. Enter “gpedit.msc” in the Start Search box.
2. Open “Computer Configuration”/Windows Settings/Security Settings/Local Policies/Security Settings.
3. In the right pane, enable the following policies:

Network access: Allow anonymous SID/name translation
Network access: Let Everyone permissions apply to anonymous users

Also please disable the following policies.

Network access: Restrict anonymous access to Named Pipes and Shares
Network access: Do not allow anonymous enumeration of SAM accounts
Network access: Do not allow anonymous enumeration of SAM accounts and shares
————————————————————————————————————–
For my pc I set following setting:

I fixed this probleme – windows 7 can not connect to share on server 2003, by this single step:

Browse to “Local Policies” -> “Security Options”. Now look for the entry “Network Security: LAN Manager authentication level” and open it. Click on the dropdown menu and select “Send LM & NTLM – use NTLMv2 session security if negotiated”. Apply the settings.

Referecen link: http://social.technet.microsoft.com/Forums/en-US/w7itpronetworking/thread/68ffbe2a-09a7-4e29-859c-ca1aaf75dcd1/

Service Unavailable

IIS 6.0 supports both the 32-bit mode and the 64-bit mode. However IIS 6.0 does not support running both modes at the same time on a 64-bit version of Windows. ASP.NET 1.1 runs only in 32-bit mode. ASP.NET 2.0 runs in 32-bit mode or in 64-bit mode. Therefore, if you want to run ASP.NET 1.1 and ASP.NET 2.0 at the same time, you must run IIS in 32-bit mode.
ASP.NET 1.1, 32-bit version

// To run the 32-bit version of ASP.NET 1.1, follow these steps:

1. Click Start, click Run, type cmd, and then click OK.
2. Type the following command to enable the 32-bit mode:
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1
3. Type the following command to install the version of ASP.NET 1.1 and to install the script maps at the IIS root and under:
%SYSTEMROOT%\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -i
4. Make sure that the status of ASP.NET version 1.1.4322 is set to Allowed in the Web service extension list in Internet Information Services Manager.

ASP.NET 2.0, 32-bit version

// To run the 32-bit version of ASP.NET 2.0, follow these steps:

1. Click Start, click Run, type cmd, and then click OK.
2. Type the following command to enable the 32-bit mode:
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1
3. Type the following command to install the version of ASP.NET 2.0 (32-bit) and to install the script maps at the IIS root and under:
%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i
4. Make sure that the status of ASP.NET version 2.0.50727 (32-bit) is set to Allowed in the Web service extension list in Internet Information Services Manager.

ASP.NET 2.0, 64-bit version

// To run the 64-bit version of ASP.NET 2.0, follow these steps:

1. Click Start, click Run, type cmd, and then click OK.
2. Type the following command to disable the 32-bit mode:
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 0
3. Type the following command to install the version of ASP.NET 2.0 and to install the script maps at the IIS root and under:
%SYSTEMROOT%\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis.exe -i
4. Make sure that the status of ASP.NET version 2.0.50727 is set to Allowed in the Web service extension list in Internet Information Services Manager.

Ref : http://support.microsoft.com/kb/894435

SSL connection iphone

Here I have posted code how to calling “Web service” which are SSL enabled. like “https://test.com/testservice.svc/gettest”

#import “Hello_SOAPViewController.h”
@interface NSURLRequest (withHttpsCertificates)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
@end

@implementation Hello_SOAPViewController

NSMutableData *webData;

– (void)viewDidLoad {

//////////////////////////////////////////////////

//Web Service Call

//////////////////////////////////////////////////

NSURL *url = [NSURL URLWithString:@”https://test.com/testservice.svc/gettest”];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];

[theRequest addValue:@”application/x-www-form-urlencoded” forHTTPHeaderField:@”Content-Type”];

[theRequest setHTTPMethod:@”GET”];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if(theConnection) {
webData = [[NSMutableData data] retain];
}
else {
NSLog(@”theConnection is NULL”);
}

}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{

NSLog(@”ERROR with theConnection:%@”,[error description]);
if ([error code] == -1001 ){//isEqualToString:@”timed out”]) {
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@”Connection Error” message:@”Server Unresponsive” delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil] autorelease];
[alertView show];

}else{
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@”Connection Error” message:@”Check your internet connection ” delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil] autorelease];
[alertView show];
}

[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@”DONE. Received Bytes: %d”, [webData length]);

///////////////////////
//Process Your Data here:

///////////////////////

[connection release];
[webData release];

}

– (void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren’t in use.
}

– (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

– (void)dealloc {

[super dealloc];
}

Source code:
http://cid-efc0ec2e2cd761ee.office.live.com/self.aspx/.Public/SSL%5E_iPhone%5E_Connection.zip