用C#写服务器程序连接本地SQL SERVER,该怎么写?

protected void ImageButton1_Click(object sender, EventArgs e)
{
string UserName = Request.Form["Username"].ToString().Trim();
string UserPwd = Request.Form["pwd"].ToString().Trim();
SqlConnection scon = dtcon.getcon();
scon.Open();
SqlCommand cmd = scon.CreateCommand();
cmd.CommandText = getStrSQL(this.DropDownList1.Text);
int count = Convert.ToInt32(cmd.ExecuteScalar());
scon.Close();
if (count > 0)
{
Session["UserName"] = UserName;
Session["UserName1"] = this.DropDownList1.Text;
int rankID = getRankID(this.DropDownList1.Text);
Response.Redirect("Admin/" + transfer(rankID));
}
else
{
MessageBox.Show(this.Page, "请正确输入!");
this.Username.Text = "";
this.pwd.Text = "";
MessageBox.SetFocus(this.Username, this.Page);
return;
}


参考一下:http://www.cnblogs.com/bluestorm/p/3368466.html

数据库连接地址用本地的ip,其他都一样
Data Source=121.40.177.64//这边换成你的ip地址 //;Initial Catalog=TestRongp2c;User ID=ceshi;Password=testrong201501

图片说明
在web.config文件中配置:


<!---->

注意:数据库一定要给该用户对该数据库的操作权限

connectionString="Data Source=.;Initial Catalog=数据库名称;UID=账户;PWD=密码;"

http://blog.csdn.net/mine3333/article/details/6258968