当前位置:主页 > 技术专题 > 数据库 >

    连接数据库的方法

    2010-09-27 14:49 作者:admin 来源:admin 浏览次数:

    public class DBCon
        {
            PRivate OleDbConnection conn = null;
            private string strCon;
            public DBCon()
            {
                strCon = HttpContext.Current.Server.MapPath("~/Data/test.mdb");

            }
            //连接access数据库
            public OleDbConnection getConn()
            {
                try
                {
                    if (conn == null || conn.State == ConnectionState.Closed)
                    {
                        conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + strCon);
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
                return conn;
            }

    }

        public class DBCon
        {
            private SqlConnection conn = null;
            private string strCon;
            public DBCon()
            {
                strCon = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;

            }
            //连接sqlserver2000 或者 2005数据库
            public SqlConnection getConn()
            {
                try
                {
                    if (conn == null || conn.State == ConnectionState.Closed)
                    {
                        conn = new SqlConnection(strCon);
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
                return conn;
            }

        }

联系方式 | 收费标准 | 上门服务 | 公司简介 | 汇款账户

回天时代有限公司

杭州公司: 杭州市文三路388号钱江科技大厦10楼1016室

华东总部:上海市徐汇区漕溪北路41号汇嘉大厦12楼E室(太平洋一期12楼)

咨询热线:400-889-1122(全国),0512-66099871(苏州),021-58358765(上海),0571-88218821(杭州) 24小时热线:13524645444,案:浙ICP备06024533号