asp .net连接打开数据库初步
2014-11-25 17:38
120 查看
1 //测试连接字符串是否成功
2 #region
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Web;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Data.SqlClient;
10 using System.Configuration;
11
12 public partial class test_Default : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16 string str = ConfigurationManager.ConnectionStrings["haqiuConnectionString"].ConnectionString;
17 SqlConnection strConn = new SqlConnection(str);
18 if (strConn == null)
19 {
20 Response.Write("连接字符串为空!");
21 }
22 else
23 {
24 Response.Write("连接字符串不为空!");
25 }
26 }
27 }
28 #endregion
29
30 //打开数据库连接
31 #region
32 using System;
33 using System.Collections.Generic;
34 using System.Linq;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38 using System.Data.SqlClient;
39 using System.Configuration;
40
41 public partial class test_Default : System.Web.UI.Page
42 {
43 protected void Page_Load(object sender, EventArgs e)
44 {
45 string str = ConfigurationManager.ConnectionStrings["haqiuConnectionString"].ConnectionString;
46 SqlConnection strConn = new SqlConnection(str);
47 if (strConn.State.ToString()=="Closed")
48 {
49 strConn.Open();
50 Response.Write("数据库连接已经打开!");
51 }
52 else
53 {
54 Response.Write("数据库连接无法打开!");
55 }
56 }
57 }
58 #endregion
59
WebDriver
2 #region
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Web;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Data.SqlClient;
10 using System.Configuration;
11
12 public partial class test_Default : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16 string str = ConfigurationManager.ConnectionStrings["haqiuConnectionString"].ConnectionString;
17 SqlConnection strConn = new SqlConnection(str);
18 if (strConn == null)
19 {
20 Response.Write("连接字符串为空!");
21 }
22 else
23 {
24 Response.Write("连接字符串不为空!");
25 }
26 }
27 }
28 #endregion
29
30 //打开数据库连接
31 #region
32 using System;
33 using System.Collections.Generic;
34 using System.Linq;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38 using System.Data.SqlClient;
39 using System.Configuration;
40
41 public partial class test_Default : System.Web.UI.Page
42 {
43 protected void Page_Load(object sender, EventArgs e)
44 {
45 string str = ConfigurationManager.ConnectionStrings["haqiuConnectionString"].ConnectionString;
46 SqlConnection strConn = new SqlConnection(str);
47 if (strConn.State.ToString()=="Closed")
48 {
49 strConn.Open();
50 Response.Write("数据库连接已经打开!");
51 }
52 else
53 {
54 Response.Write("数据库连接无法打开!");
55 }
56 }
57 }
58 #endregion
59
WebDriver
相关文章推荐
- ASP.NET中数据库的操作初步----连接并且打开数据库
- ASP.NET中数据库的操作初步----连接并且打开数据库
- ASP.NET中数据库的操作初步----连接并且打开数据库
- win7 ASP.NET 安全选项卡无法打开(无法连接到 SQL Server 数据库)的解决办法
- ASP.NET 2.0里轻松获取数据库连接统计数据
- 郁闷ing!有没有谁可以提供asp.net一个数据库连接的例子
- asp.net with c#连接sql 2000数据库
- ASP.NET 中数据库操作初步
- ASP.net 数据库的连接
- 在ASP.NET(C#)中使用Oralce Object For OLE 2.3连接Oracle 8.0.5数据库!
- ASP.NET中使用web.config配置web应用程序中的数据库连接
- ASP.net数据库连接相关代码?
- 用WINXP2+DW+ACCESS使用本地 ASP.NET 和 ASP 服务器时数据库连接失败
- asp.net连接数据库
- asp.net/C#连接数据库
- ASP.NET中的数据库连接
- asp.net(vb.net)连接sql server 2000数据库的连接模块(module)
- asp.net 连接数据库基础
- ASP.NET中使用web.config配置web应用程序中的数据库连接
- ASP.NET中数据库的操作初步----DataSet操作数据库