Sunday, April 19, 2009

failed to enable constriants,One or more rows contain values violating non-null, unique

Error:asp.net/c#/typed data set,strong datasets,xsd files
"failed to enable constriants,One or more rows contain values violating non-null, unique"

If this is the error you get into your dataset/xsd files then there is a problem with the table u r using to fetch records.You might have altered the datatype/length of the column.

the best way to resolve it is to re create the dataset/xsd file or use a simple stored procedure to fetch records...

Wednesday, April 8, 2009

The SMTP server requires a secure connection or the client was not authenticated. The server response was: denied access

Error while sending email...asp.net 2.0

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: denied access

Reliable $1 Web Hosting by 3iX

you can resolve this error by setting
mailclient.UseDefaultCredentials = true; in the code you are using to send email. use this code

System.Net.Mail.SmtpClient mailclient = new System.Net.Mail.SmtpClient();
System.Net.NetworkCredential auth = new System.Net.NetworkCredential("support@abc.com", "123#");
mailclient.Host = "mail.abc.com";
mailclient.UseDefaultCredentials = true;
mailclient.Credentials = auth;
mailclient.Send(msg);

Sunday, December 14, 2008

Stored Procudre to Find next 5 records alphabetically

Stored procedure to find next 5 records alphabetically.Like next 5 records with alphabets starting from a will be b,c,d,e,f

----------

Reliable $1 Web Hosting by 3iX
-------------

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
Create PROCEDURE [dbo].[FindNext5RecordsByCharacter]
(
@CityCharacter char(1)
)
AS
BEGIN
declare @alpha varchar(1)
declare @alpha1 varchar(1)
declare @alpha2 varchar(1)
declare @alpha3 varchar(1)
declare @alpha4 varchar(1)
declare @alpha5 varchar(1)
if (@CityCharacter='y' or @CityCharacter='Y')
begin
set @CityCharacter='a'
set @alpha=@CityCharacter
select @alpha1= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha order by CityName desc
--print @alpha1
select @alpha2= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha1 order by CityName desc
--print @alpha2
select @alpha3= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha2 order by CityName desc
--print @alpha3
select @alpha4= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha3 order by CityName desc
--print @alpha4
end
else if(@CityCharacter<>'z' or @CityCharacter<>'Z' )
begin
set @alpha=@CityCharacter
select @alpha1= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha order by CityName desc
--print @alpha1
select @alpha2= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha1 order by CityName desc
--print @alpha2
select @alpha3= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha2 order by CityName desc
--print @alpha3
select @alpha4= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha3 order by CityName desc
--print @alpha4
end
else
begin
set @CityCharacter='a'
set @alpha=@CityCharacter
select @alpha1= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha order by CityName desc
--print @alpha1
select @alpha2= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha1 order by CityName desc
--print @alpha2
select @alpha3= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha2 order by CityName desc
--print @alpha3
select @alpha4= substring(CityName,1,1) from tbl_city where substring(CityName,1,1) > @alpha3 order by CityName desc
--print @alpha4
end

CREATE TABLE #Temp(
CityId int,
CityName char(30) )

INSERT INTO #Temp (CityId, CityName)
SELECT top 1 CityId, CityName
FROM tbl_city where substring(CityName,1,1) >@alpha
INSERT INTO #Temp (CityId, CityName)
SELECT top 1 CityId, CityName
FROM tbl_city where substring(CityName,1,1) >@alpha1
INSERT INTO #Temp (CityId, CityName)
SELECT top 1 CityId, CityName
FROM tbl_city where substring(CityName,1,1) >@alpha2
INSERT INTO #Temp (CityId, CityName)
SELECT top 1 CityId, CityName
FROM tbl_city where substring(CityName,1,1) >@alpha3
INSERT INTO #Temp (CityId, CityName)
SELECT top 1 CityId, CityName
FROM tbl_city where substring(CityName,1,1) >@alpha4
INSERT INTO #Temp (CityId, CityName)
SELECT top 1 CityId, CityName
FROM tbl_city where substring(CityName,1,1) >@alpha5

select * from #temp
drop table #temp
END

Thursday, November 13, 2008

Implementing St George Payment Gateway using asp.net or c#


St.George Internet Payment Gateway
In order to implement internet payment gateway using St George api,using asp.net and c# you require followings things


Reliable $1 Web Hosting by 3iX

1) webpay.dll and Org.Mentalis.Security.dll
2) Client Id from the st george bank
3) digital certificate and its pwd from the bank

then in the pay button click paste the following code

Int32 pay1 = Convert.ToInt32(amount.Text);
if (pay1>=pay)
{
//Set the following values appropriately for your Bank/Service Provider
//String responseURL = "http://www.gwipg.stgeorge.com.au/";
String responseURL = "";

//To avoid processing duplicate payments, for this user, check the
//if ( Session.Contents[ "WEBPAYOBJECT" ] == null )
//{
webpay.client.Webpay w = new webpay.client.Webpay("10000xxx", "e:\\net.pfx", "yourpwd");
Session.Contents["WEBPAYOBJECT"] = w;
responseURL = processPayment(w);
String expdate = mm.SelectedValue + "/" + yy.SelectedValue;
obj.Insert(Convert.ToInt32(Session["MId"]), Convert.ToDecimal(amount.Text), ddlpaymentmethod.SelectedValue, cardName.Text, txtCardData.Text, cvc2.Text, expdate.ToString());
//}
Response.Redirect(responseURL);
}
else
{
lblpayment.Text = "Payment Should be greater than " + pay;
}



use the following function


private String processPayment(webpay.client.Webpay w)
{
System.Random randObj = new System.Random(5325);
w.setServers("www.gwipg.stgeorge.com.au");
w.setPort(3006); //use 3005 for testing
w.setValue("CLIENTID", "10000xxx");

w.setValue("INTERFACE", "CREDITCARD");
w.setValue("TRANSACTIONTYPE", "PURCHASE");
//Set the following values based on user input, or calculations from other parts of
//your application.
//Please consult your service provider's documentation for
//required and optional fields.
w.setValue("CARDHOLDER_NAME", cardName.Text);
w.setValue("CARDDATA", txtCardData.Text);
w.setValue("CARDEXPIRYDATE", mm.SelectedValue + yy.SelectedValue);
w.setValue("CVC2", cvc2.Text);

w.setValue("TOTALAMOUNT", amount.Text);
w.setValue("CLIENTREF", "" + randObj.Next());

//Store the Webpay Object in the session. So it can be retrieved easily by other pages (results/errors, etc)
Session.Contents["WEBPAYOBJECT"] = w;

System.Exception ex = null;
for (int i = 0; i < 2; i++)
{
try
{
w.execute();
ex = null;
break;
}
catch (webpay.client.ConnectException cex)
{
//Log the error, and try again.
ex = cex;
continue;
}
catch (System.Exception ioex)
{
//If a TXNREFERENCE is available, check the status of the transaction.
//The number of times to loop, and the sleep time may vary depending on the
//requirements of your application.
ex = ioex;
w.setValue("TRANSACTIONTYPE", "STATUS");
for (int j = 0; j < 2; j++)
{
try
{
//In case we the connection was dropped part way thru,
//give the transacton time to complete at the back end
System.Threading.Thread.Sleep(1500);
}
catch (Exception e)
{
}
try
{
w.execute();
//If the responsecode is still "IP", then wait and check the status again.
if (w.getValue("RESPONSECODE") != "IP")
{
//We have a result, continue
break;
}
}
catch (System.Exception e)
{
ex = e;
}
}
}
}
if (ex != null)
{
//An exception was encounteded which could not be recovered, possibly
//while attempting to retry or check status. Set the redirect to a
//page/process which can handle error conditions.
Session.Contents["ERROR"] = ex;
return "ErrorPage.aspx";
}
//Processing completed normally - redirect and display the results to the user.
//NOTE: Your applicaton will need also need to inspect the RESPONSECODE parameter and
//store the transaction result somewhere. This should be done here, and not in the
//Result display code, as this code will only execute once, while the display code has the potential
//to be re-executed if the user clicks "Refresh" or attempts to re-process the transaction
//using the "Back" button.
return "ResultsPage.aspx";
}

}
// if you face any problem please feel free to ask