Adsence750x90

Thursday, April 17, 2008

How to configure SQL Server 2005 to allow remote connections

How to configure SQL Server 2005 to allow remote connections




INTRODUCTION
When you try to connect to an instance of Microsoft SQL Server 2005 from a remote computer, you may receive an error message. This problem may occur when you use any program to connect to SQL Server. For example, you receive the following error message when you use the SQLCMD utility to connect to SQL Server:
Sqlcmd: Error: Microsoft SQL Native Client: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.
This problem may occur when SQL Server 2005 is not configured to accept remote connections. By default, SQL Server 2005 Express Edition and SQL Server 2005 Developer Edition do not allow remote connections. To configure SQL Server 2005 to allow remote connections, complete all the following steps:
• Enable remote connections on the instance of SQL Server that you want to connect to from a remote computer.
• Turn on the SQL Server Browser service.
• Configure the firewall to allow network traffic that is related to SQL Server and to the SQL Server Browser service.
This article describes how to complete each of these steps.


MORE INFORMATION
To enable remote connections on the instance of SQL Server 2005 and to turn on the SQL Server Browser service, use the SQL Server 2005 Surface Area Configuration tool. The Surface Area Configuration tool is installed when you install SQL Server 2005.


Enable remote connections for SQL Server 2005 Express or SQL Server 2005 Developer Edition
You must enable remote connections for each instance of SQL Server 2005 that you want to connect to from a remote computer. To do this, follow these steps:
1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
2. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
3. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply.

Note Click OK when you receive the following message:
Changes to Connection Settings will not take effect until you restart the Database Engine service.
4. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Service, click Stop, wait until the MSSQLSERVER service stops, and then click Start to restart the MSSQLSERVER service.


Enable the SQL Server Browser service
If you are running SQL Server 2005 by using an instance name and you are not using a specific TCP/IP port number in your connection string, you must enable the SQL Server Browser service to allow for remote connections. For example, SQL Server 2005 Express is installed with a default instance name of Computer Name\SQLEXPRESS. You are only required to enable the SQL Server Browser service one time, regardless of how many instances of SQL Server 2005 you are running. To enable the SQL Server Browser service, follow these steps.

Important These steps may increase your security risk. These steps may also make your computer or your network more vulnerable to attack by malicious users or by malicious software such as viruses. We recommend the process that this article describes to enable programs to operate as they are designed to, or to implement specific program capabilities. Before you make these changes, we recommend that you evaluate the risks that are associated with implementing this process in your particular environment. If you choose to implement this process, take any appropriate additional steps to help protect your system. We recommend that you use this process only if you really require this process.
1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
2. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
3. On the Surface Area Configuration for Services and Connections page, click SQL Server Browser, click Automatic for Startup type, and then click Apply.

Note When you click the Automatic option, the SQL Server Browser service starts automatically every time that you start Microsoft Windows.
4. Click Start, and then click OK.
Note When you run the SQL Server Browser service on a computer, the computer displays the instance names and the connection information for each instance of SQL Server that is running on the computer. This risk can be reduced by not enabling the SQL Server Browser service and by connecting to the instance of SQL Server directly through an assigned TCP port. Connecting directly to an instance of SQL Server through a TCP port is beyond the scope of this article. For more information about the SQL Server Browser server and connecting to an instance of SQL Server, see the following topics in SQL Server Books Online:
• SQL Server Browser Service
• Connecting to the SQL Server Database Engine
• Client Network Configuration


Create exceptions in Windows Firewall
These steps apply to the version of Windows Firewall that is included in Windows XP Service Pack 2 (SP2) and in Windows Server 2003. If you are using a different firewall system, see your firewall documentation for more information.

If you are running a firewall on the computer that is running SQL Server 2005, external connections to SQL Server 2005 will be blocked unless SQL Server 2005 and the SQL Server Browser service can communicate through the firewall. You must create an exception for each instance of SQL Server 2005 that you want to accept remote connections and an exception for the SQL Server Browser service.

SQL Server 2005 uses an instance ID as part of the path when you install its program files. To create an exception for each instance of SQL Server, you must identify the correct instance ID. To obtain an instance ID, follow these steps:
1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Configuration Manager.
2. In SQL Server Configuration Manager, click the SQL Server Browser service in the right pane, right-click the instance name in the main window, and then click Properties.
3. On the SQL Server Browser Properties page, click the Advanced tab, locate the instance ID in the property list, and then click OK.
To open Windows Firewall, click Start, click Run, type firewall.cpl, and then click OK.
Create an exception for SQL Server 2005 in Windows Firewall
To create an exception for SQL Server 2005 in Windows Firewall, follow these steps:
1. In Windows Firewall, click the Exceptions tab, and then click Add Program.
2. In the Add a Program window, click Browse.
3. Click the C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe executable program, click Open, and then click OK.

Note The path may be different depending on where SQL Server 2005 is installed. MSSQL.1 is a placeholder for the instance ID that you obtained in step 3 of the previous procedure.
4. Repeat steps 1 through 3 for each instance of SQL Server 2005 that needs an exception.
Create an exception for the SQL Server Browser service in Windows Firewall
To create an exception for the SQL Server Browser service in Windows Firewall, follow these steps:
1. In Windows Firewall, click the Exceptions tab, and then click Add Program.
2. In the Add a Program window, click Browse.
3. Click the C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe executable program, click Open, and then click OK.

Note The path may be different depending on where SQL Server 2005 is installed.

source from microsoft

Monday, April 7, 2008

Send Emails Using Gmail Account With Attachment file in ASP.Net - SMTP mail

Send Emails Using Gmail Account With Attachment file(ASP.NET /C#)

Description

you can send emails via your application using your gmail account.first you change setting in your gmail account
step 1:
login to your gmail Account this id is used for sending emails from your application
step 2:
goto gmail settings then click on Forwarding and POP/IMAP
step 3:
In IMAP Access Check Enable IMAP
step 4:
then goto ur application use below code

C# ASP.NET CODE


ButtonClick

{

string attachmentFile = @"C:\Documents and Settings\Administrator\Desktop\testImage.jpg";
System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress("your-reciving-email@gmail.com");
System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress("fromAddress@yahoo.com");
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(fromAddress, toAddress);
mm.Subject = "Email Subject";
System.Net.Mail.Attachment mailAttachment = new System.Net.Mail.Attachment(printScreen);
mm.Attachments.Add(mailAttachment);
mm.IsBodyHtml = true;
mm.BodyEncoding = System.Text.Encoding.UTF8;
sendMail(mm);

}






private static string sendMail(System.Net.Mail.MailMessage mm)
{
try
{
string smtpHost = "smtp.gmail.com";
string userName = "your-email-address@gmail.com";//sending Id
string password = "your-password";
System.Net.Mail.SmtpClient mClient = new System.Net.Mail.SmtpClient();
mClient.Port = 587;
mClient.EnableSsl = true;
mClient.UseDefaultCredentials = false;
mClient.Credentials = new NetworkCredential(userName, password);
mClient.Host = smtpHost;
mClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
mClient.Send(mm);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

Get Week Of The Year in C# ASP.NET - sample source code


Get Week Of The Year

C# ASP.NET code For get WEEk from a year.


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class WeekCalc : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
Response.Write(getWeek(DateTime.Now));
}
public int getWeek(DateTime date)
{
System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("no");
System.Globalization.Calendar cal = cult_info.Calendar;
int weekCount = cal.GetWeekOfYear(date, cult_info.DateTimeFormat.CalendarWeekRule, cult_info.DateTimeFormat.FirstDayOfWeek);
return weekCount;

}


ASP.NET C# Code for Get Zodiac Sign - source code

Description: Zodiac Sign ASP.NET-C#

when Date of Birth pass to my function ZodiacSign() it return Zodiac Sign of that DOB
giving the fuction only u can pass DateTime value into ZodiacSign()


public string ZodiacSign(DateTime DateOfBirth)
{
string returnString = string.Empty;
string[] dateAndMonth = DateOfBirth.ToLongDateString().Split(new char[] { ',' });
string[] ckhString = dateAndMonth[1].ToString().Split(new char[] { ' ' });
if (ckhString[1].ToString() == "March")
{
if (Convert.ToInt32(ckhString[2]) <= 20) { returnString = "Pisces"; } else { returnString = "Aries"; } } else if (ckhString[1].ToString() == "April") { if (Convert.ToInt32(ckhString[2]) <= 19) { returnString = "Aries"; } else { returnString = "Taurus"; } } else if (ckhString[1].ToString() == "May") { if (Convert.ToInt32(ckhString[2]) <= 20) { returnString = "Taurus"; } else { returnString = "Gemini"; } } else if (ckhString[1].ToString() == "June") { if (Convert.ToInt32(ckhString[2]) <= 20) { returnString = "Gemini"; } else { returnString = "Cancer"; } } else if (ckhString[1].ToString() == "July") { if (Convert.ToInt32(ckhString[2]) <= 22) { returnString = "Cancer"; } else { returnString = "Leo"; } } else if (ckhString[1].ToString() == "August") { if (Convert.ToInt32(ckhString[2]) <= 22) { returnString = "Leo"; } else { returnString = "Virgo"; } } else if (ckhString[1].ToString() == "September") { if (Convert.ToInt32(ckhString[2]) <= 22) { returnString = "Virgo"; } else { returnString = "Libra"; } } else if (ckhString[1].ToString() == "October") { if (Convert.ToInt32(ckhString[2]) <= 22) { returnString = "Libra"; } else { returnString = "Scorpio"; } } else if (ckhString[1].ToString() == "November") { if (Convert.ToInt32(ckhString[2]) <= 21) { returnString = "Scorpio"; } else { returnString = "Sagittarius"; } } else if (ckhString[1].ToString() == "December") { if (Convert.ToInt32(ckhString[2]) <= 21) { returnString = "Sagittarius"; } else { returnString = "Capricorn"; } } else if (ckhString[1].ToString() == "January") { if (Convert.ToInt32(ckhString[2]) <= 19) { returnString = "Capricorn"; } else { returnString = "Aquarius"; } } else if (ckhString[1].ToString() == "February") { if (Convert.ToInt32(ckhString[2]) <= 18) { returnString = "Aquarius"; } else { returnString = "Pisces"; } } return returnString; }

ASP.NET AJAX DropDownList

ASP.NET AJAX DropDownList

html Code
@asp:dropdownlist id="ddlCountry" runat="server" onselectedindexchanged="ddlCountry_SelectedIndexChanged" autopostback="True"@@/asp:dropdownlist@
@asp:updatepanel id="upnl" runat="server"@
@contenttemplate@
@asp:dropdownlist id="ddlState" runat="server"@@/asp:dropdownlist@
@/contenttemplate@
@triggers@


@asp:asyncpostbacktrigger controlid="ddlCountry"@
@/asp:asyncpostbacktrigger@
@/triggers@



protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
SqlConnection con = new SqlConnection("Data Source=SERVER; Integrated Security=SSPI;persist security info=True;Initial Catalog=DBNAME;");
SqlCommand cmd = new SqlCommand("SELECT CountryName,CountryId FROM CountryTable", con);
DataTable dt = new DataTable();
con.Open();
SqlDataAdapter adptr = new SqlDataAdapter(cmd);
adptr.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
ddlCountry.Items.Clear();
ddlCountry.Items.Add("SELECT");
foreach (DataRow drow in dt.Rows)
{
ListItem lst = new ListItem();
lst.Value = drow[1].ToString();
lst.Text = drow[0].ToString();
ddlCountry.Items.Add(lst);
}
}
}

}

protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlCountry.SelectedValue.ToString() != "SELECT")
{
SqlConnection con = new SqlConnection("Data Source=SERVER; Integrated Security=SSPI;persist security info=True;Initial Catalog=DBNAME;");
SqlCommand cmd = new SqlCommand(string.Format("SELECT StateName,StateId FROM StateTable WHERE CountryId='{0}'", ddlCountry.SelectedValue.ToString()), con);
DataTable dt = new DataTable();
con.Open();
SqlDataAdapter adptr = new SqlDataAdapter(cmd);
adptr.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
ddlState.Items.Clear();
ddlState.Items.Add("SELECT");
foreach (DataRow drow in dt.Rows)
{
ListItem lst = new ListItem();
lst.Value = drow[1].ToString();
lst.Text = drow[0].ToString();
ddlState.Items.Add(lst);
}
}
}
}

Tuesday, April 1, 2008

AJAX Example - request and response codes

The keystone of AJAX is the XMLHttpRequest object.

Different browsers use different methods to create the XMLHttpRequest object.

Internet Explorer uses an ActiveXObject,

while other browsers(Mozilla,Netscape,Opera..) uses the built-in JavaScript object called XMLHttpRequest.

To create this object, and deal with different browsers, we are going to use a "try and catch" statement.
between script tag u can write this code to detect browser
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
}

AJAX - Sending a Request to the Server

To send off a request to the server, we use the open() method and the send() method.

The open() method takes three arguments. The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously. The send() method sends the request off to the server. If we assume that the HTML and ASP file are in the same directory, the code would be:

xmlHttp.open("GET","url",true);
xmlHttp.send(null);



xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.Form_elemet.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","default.aspx",true);
xmlHttp.send(null);

Source