连接数据库
像我们用vs连接数据库,写webconfig 配置 。我一般操作的数据库和应用程序都是在同一台机器或同一个局域网上的同一网段上,请问下 数据库与应用程序 可以在不同的网段上,或者是网络上的两个终端。如果行,能讲下吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
/**********************************/
using System.Data;
using System.Data.SqlClient;
/**********************************/
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ss = "Data Source = NOAWAY-PC;database = photo;Integrated Security = True;";
string cc = "select * from PHOTO_ALBUMS";
SqlConnection thisConnection = new SqlConnection(ss); //只能对sql的连接
thisConnection.Open();
SqlCommand thisCommand = new SqlCommand(cc,thisConnection); //相应的sql语句发送到
DataSet ds;
SqlDataAdapter sda = new SqlDataAdapter(cc,thisConnection);
ds = new DataSet();
sda.Fill(ds,"table");
GridView1.DataSource = ds;
GridView1.DataMember = "table";
GridView1.DataBind();
}
}