• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
gooliugle
博客园    首页    新随笔    联系   管理    订阅  订阅
C# 连接各种数据库总结。

1、连接Access

 

代码
 1 public static OleDbConnection getConn()
 2 {
 3             OleDbConnection Conn=null;
 4             string StrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\AccessDataBase\GuangXi.mdb";
 5             try
 6             {
 7                 if (File.Exists(@"D:\AccessDataBase\GuangXi.mdb"))
 8                 {
 9                     Conn = new OleDbConnection(StrConn);
10                     Conn.Open();
11                 }         
12                 return Conn;
13             }
14             catch
15             {
16                 return null;
17             }
18 }


2、连接Oracle

 

代码
 1 public static OracleConnection getConn()
 2 {
 3             string strConn = "Data Source=hvmdata;Persist Security Info=True;User ID=sysadmin;Password=adminsys;Unicode=True";
 4             try
 5             {
 6                 OracleConnection Conn = new OracleConnection(strConn);
 7                 if (Conn.State != ConnectionState.Open)
 8                 {
 9                     Conn.Open();
10                 }
11                 return Conn;
12             }
13             catch
14             {
15                 return null;
16             }
17 }


3、连接Sql Server2005

代码
 1 public static SqlConnection getConn()
 2 {
 3             string strConn = "Data Source=JFD\\SQLEXPRESS;database=mydayta;uid=sa;pwd=123456;";
 4             try
 5             {
 6                 SqlConnection Conn = new SqlConnection(strConn);
 7                 if (Conn.State != ConnectionState.Open)
 8                 {
 9                     Conn.Open();
10                 }
11                 return Conn;
12             }
13             catch
14             {
15                 return null;
16             }
17 }


 

posted on 2010-04-27 17:35  gooliugle  阅读(445)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3