using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data.SqlClient;namespace Exercise
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
public string strViewString = "CategoryID";
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
int i=0;
  OleDbConnection cn;
     string strConn;

解决方案 »

  1.   

    web.config:<appSettings>
    <add key="connectionstring" value="server=dbserver\commerce;database=powersoft.com;uid=sa;password=admin" />
    </appSettings>调用:
    Dim Conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
      

  2.   

    OleDbConnection cn;
         string strConn;
    这种对象可以写在一个类里,在session开始的时候就实例化这个类,就可以调用了
      

  3.   

    楼上所说的是一种办法 比较通用
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
           <appSettings>
            <add key="sqlConnectionString" value="data source=F4;initial catalog=HFDB;integrated security=SSPI;persist security info=False;workstation id=F4;packet size=4096" >
            </add>
    </appSettings>....</configuration>
    用的时候就System.Data.SqlClient.SqlConnection Conn = New SqlClient.SqlConnection    Dim String sqlConnectionString = ConfigurationSettings.AppSettings("sqlConnectionString");另外一种办法就是
    新建模块
    在模块中写
    public   OleDbConnection cn;
    public    string strConn;
    同样是全局变量
      

  4.   

    我用的是C#.net有没有简单,直接点了阿我只是想定义一个全局的cn对象
    在Global.asax得app_start中打开数据连接对象
    在其他页中直接使用cn对象
      

  5.   

    对于配置信息可写在web.config中也可写在application中。
      

  6.   

    我用的是C#.net有没有简单,直接点了阿我只是想定义一个全局的cn对象
    在Global.asax得app_start中打开数据连接对象
    在其他页中直接使用cn对象
      

  7.   

    写一个类,然后在类中使用static定义变量,就是全局的了
      

  8.   

    保存在 APPLICATION 中,也可在 GLOBAL.ASAX 中加载
      

  9.   

    用appliction定义一个appliction类的变量就好了
      

  10.   

    同意liguiman(li) :
        也可以写成类,
        其实模块就够了我不赞同存放在 application 中,不如定义在模块中作为全局变量那么直接!不过 asp.net 访问数据库提供连接池机制,打开连接后随手关闭也不影响效率
    没有必要再沿用原来 asp 的方式将 cn 存放在 application 或 session 中