oracle 串連資料庫

來源:互聯網
上載者:User

標籤:dev   ext   add   屬性   conf   dap   命名   tin   comm   

一、首先先引用oracle的命名空間

    System.Data.OracleClient;

二、串連資料庫代碼:

        private DataTable SqlHelper(string commadText)        {            try            {                //通過設定檔,串連資料庫                //string connectionStr = ConfigurationSettings.AppSettings["ConnectionString"].ToString();                //OracleConnection conn = new OracleConnection(connectionStr);                //直接字串串連資料庫                OracleConnection conn = new OracleConnection("Data Source=192.168.1.3;User Id=epv7;Password=epv7;Max Pool Size = 512");                conn.Open();                OracleDataAdapter sqlDA = new OracleDataAdapter(commadText, conn);                DataSet ds = new DataSet();                sqlDA.Fill(ds);                conn.Close();                return ds.Tables[0];            }            catch (Exception ex)            {                throw ex;            }        }

  三、通過設定檔串連資料庫,設定檔內容:

<configuration>  <appSettings>    <!--<add key="DBType" value="SQ"/>-->    <!--<add key="ConnectionString" value="Server=.;Database=WinStudent;uid=test;pwd=test"/>-->    <add key="ConnectionString" value="Data Source=192.168.1.113;User Id=epv7;Password=epv7;Max Pool Size = 512"/>  </appSettings></configuration>

如果出現如下錯誤:

嘗試載入 Oracle 用戶端庫時引發 BadImageFormatException。如果在安裝 32 位 Oracle 用戶端組件的情況下以 64 位元模式運行,將出現此問題  

解決方案一:

點擊要 啟動並執行解決方案--右鍵---屬性,選產生---目標平台,改為x86

解決方案二:

下載以下dll 檔案,並添加引用

         Devart.Data

         Devart.Data.Oracle

引用命名空間為:

        using Devart.Data.Oracle;

 

oracle 串連資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.