Thursday, January 29, 2009

Installing MS chart adding into vs 2008 toolbox and using MS chart with sample code


Looking on the traffic on my previous post on MS chart, I thought to give more information and give some good quality images step by step which will help everybody to install and use this controls very well.

Advantages:
1. Easy to use.
2. No third party components.
3. Attractive and pleasing.
4. Quality of charts are superb.
5. Offcourse it is free. :-) and no lic prob for this chart controls.

Here we go:
the flow of the post will be like this,
a. Requirement list
b. Steps to follow.
c. Downloading required softwares.
d. Installing.
e. Configuration of charts to VS 2008.
f. Small application to run and Show a elegant Chart.


Requirement List:

1. .NET 3.5 SP1
2. VS 2008 SP1.
2. MSChart.exe software.
3. MSChart documentation and samples for future developments.

Related Links:

Download and install in this order.
1. .NET 3.5 framework download
2. .NET 3.5 Framework SP1 download
3. VS 2008 SP1 download
4. MSChart.exe download.
5. MS chart documentation download.
6. View and download samples.

Configuration of charts to VS 2008 :
Follow the screen shots.
1. Open the toolbox and right click and select "Add Tab"


2. Name the Tab "MS Chart".
3. Right click the toolbox and select "choose items"


4. Click on browse and navigate to the folder where you have installed MS chart.
Usually it will be stored in c:\program files\Microsoft Chart Controls


5. Select the dll "System.Web.DataVisualiztion.dll".


You will find it the control in Tool box.

Next post will have basic Chart creation in web ASP.NET.

Happy charting.

Wednesday, January 28, 2009

Tuesday, January 27, 2009

Common Connection strings


MS SQL Server 2005 and MS SQL Express 2005

1. Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

2. Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;

3. Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

4. Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

5. Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;

6. Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;

7. Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

8. Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; MultipleActiveResultSets=true;

9. Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;

10. Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

11. Data Source=.\SQLExpress;Integrated Security=true; AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;

12. Data Source=myServerAddress;Failover Partner=myMirrorServerAddress;Initial Catalog=myDataBase;Integrated Security=True;

13. Server=myServerAddress;Database=myDataBase;Integrated Security=True;Asynchronous Processing=True;






SQL 2000 :
1. Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

2. Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;

3. Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
4. Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

5. Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;

6. Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;

7. Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

8. Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;Packet Size=4096;

9. Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

10. Provider=sqloledb;Data Source=myServerName\theInstanceName;Initial Catalog=myDataBase;Integrated Security=SSPI;

11. Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

12. Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;OLE DB Services=-2;

13. Provider=SQLOLEDB;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername; Password=myPassword;

14. Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

15. Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

Content Source: http://www.connectionstrings.com/sql-server

Monday, January 26, 2009

Login failed for user 'Server\ASPNET'.



Do anybody know how to solve it.
Thanks

Saturday, January 24, 2009

Simple ready code on Asp.net Error logging in Event log




Please follow this small code, which is very simple just need to copy paste and use
it comfortably for logging errors in asp.net in Event logs.

This would be like this (the error messages)



1. Global.asax

void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
General.LogErrors(ex, Request.Form.ToString(), Request.QueryString.ToString());
}

2. Create a new class in App_code
public static class General
{
static General()
{

}
public static void LogErrors(Exception ex,string Form, string QueryString)
{
try
{
// Check Error log is not full-- code has to write
EventLog.WriteEntry("Test Web",
"MESSAGE: " + ex.Message +
"\nSOURCE: " + ex.Source +
"\nFORM: " + Form +
"\nQUERYSTRING: " + QueryString +
"\nTARGETSITE: " + ex.TargetSite +
"\nSTACKTRACE: " + ex.StackTrace,
EventLogEntryType.Error);

}
finally
{
}
}

}


3. Relax and enjoy coding.

Sunday, January 11, 2009

ASP.Net Mobile Application


Q: do anybody have a good idea about how to start asp.net mobile applications in VS 2008. and any simulator, or tools which will help in designing .Net mobile application.



Thanks in advance.

Friday, January 9, 2009

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

I have membership api database,

It was working very well since 4 months, at a sudden it is giving this exception.
"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
on this line.



MembershipUser MemUser = Membership.GetUser(HttpUtility.HtmlEncode(this.LOGINCTRL.UserName));

Thursday, January 8, 2009

Sending Email using Templates Asp.net

Have you ever tried to send the emails using generic email templates.
Here is the simple method which I use to follow to send email in HTML format.

1. Create a NewAccountTemplate.htm page in "EmailTemplates" folder.
2. Enter your html contents in the htm page.
Eg:










Welcome to My Website!



Hello, ##UserName##. You are receiving this email because you recently created a new account at my
site. Before you can login, however, you need to first visit the following link:



<%VerifyUrl%>



After visiting the above link you can log into the site!



If you have any problems verifying your account, please reply to this email to
get assistance.



Thanks!











3. Create a class FileClass


public class FileClass
{
public FileClass()
{
}

public static string ReadFile(string FileName)
{
try
{
String FILENAME = System.Web.HttpContext.Current.Server.MapPath(FileName);
StreamReader objStreamReader = File.OpenText(FILENAME);
String contents = objStreamReader.ReadToEnd();
return contents;
}
catch (Exception ex)
{

}
return "";
}


public static void SendMail(string From, string To,string CC,string AttachmentFilePath ,string Subject, string Body,ref int intResult,ref string MailResult)
{

try
{
SmtpClient mailClient = new SmtpClient();
NetworkCredential basicAuthenticationInfo = new NetworkCredential();
basicAuthenticationInfo.UserName = ConfigurationManager.AppSettings["userName"].ToString();
basicAuthenticationInfo.Password = ConfigurationManager.AppSettings["password"].ToString();
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = basicAuthenticationInfo;
mailClient.Host = ConfigurationManager.AppSettings["host"].ToString();
mailClient.Port = Convert.ToInt32(ConfigurationManager.AppSettings["port"].ToString());
// mailClient.EnableSsl = true;
System.Net.Mail.MailMessage mailmessage = new System.Net.Mail.MailMessage(From, To, Subject, Body);
if(CC.Trim() !="")
mailmessage.CC.Add(CC);
System.Net.Mail.Attachment Attach =null;
if(AttachmentFilePath.Trim() !="")
Attach = new System.Net.Mail.Attachment(AttachmentFilePath);
if(Attach !=null)
mailmessage.Attachments.Add(Attach);
mailmessage.IsBodyHtml = true;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.EnableSsl = true;
mailmessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailmessage.BodyEncoding = System.Text.Encoding.UTF8;



mailClient.Send(mailmessage);
MailResult = "Mail(s) sent successfully.";
intResult = 0;
}
catch(Exception ex)
{
MailResult = "Mail Unsuccessful : "+ex;
intResult = -1;
//if( ex.ToString() = "System.UnauthorizedAccessException")
//{
// MailResult +="Please give the ASP Net permission to the file before attachment.";
//}

}
}


}



4. call this function from your aspx page.
public string GetRegisterTemplate()
{
return FileClass.ReadFile("EmailTemplates/NewAccountTemplate.htm");
}


5.Code to send Email :

public void SendEmailVerificationToUser(string strUsername)
{
// getting the content of the Email template.
string body = GetRegisterTemplate();
// replace your username with dynamic name and URL and other based on your
requirements
body = body.Replace("##UserName##", userinfo.UserName);
body = body.Replace("##VerifyUrl##", verifyURL);
int intResult = 0;
string strMailResult = "";
FileClass.SendMail("xyz@gmail.com", userinfo.Email, "", "", "Organisation Welcomes: Activation mail...", body, ref intResult, ref strMailResult);
}


For download of the source code plz leave your email.

Happy coding.

Wednesday, January 7, 2009

How to open oledata.mso

Most of them who do use MS word and send the same as attachment in the mail might have faced or may face the oledata.mso problem.






cause is inline changes of the word doc in outlook and sending the same mail.

1.Please refer details from microsoft.
http://support.microsoft.com/?kbid=222330
2. from a blog
http://forums.cnet.com/5208-6129_102-0.html?forumID=29&threadID=12465&messageID=142069

3. The best method :
Most of them use gmail and opening in gmail by clicking
"View entire message"