using System.Data.OracleClient; string connectStr = "Data Source = DBS_MESV1;User = MESV1;Password = MESV1";
VS可能会出现警告 1 “System.Data.OracleClient.OracleConnection”已过时,但不影响数据库的连接,如果感觉烦的话,可以在引用中添加Oracle.DataAccess.dll,这个dll在Oracle安装目录下的bin目录下,然后使用Oracle.DataAccess.Client命名空间:
using Oracle.DataAccess.Client; string connectStr = "Data Source = DBS_MESV1;User ID = MESV1;Password = MESV1";
注意此时连接字符串中User字段是不合法的,要使用User ID,连接代码如下:
string connectStr = "Data Source = DBS_MESV1;User = MESV1;Password = MESV1"; OracleConnection myCon = new OracleConnection(connectStr); try { myCon.Open(); MessageBox.Show(myCon.State.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { myCon.Close(); }