0

我正在尝试使用 Oracle.ManagedDataAccess.Client 作为 SYSDBA 从 C# 桌面应用程序连接到 Windows 7 64x 版本上的 ORACLE 10g 数据库。

这是我来自配置文件的连接字符串:

<add name="default" connectionString="User Id=scott;Password=tiger;DBA Privilege=SYSDBA;Data Source=(DESCRIPTION =(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = sherif-PC)(PORT = 1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME =orcl2)));" providerName="Oracle.ManagedDataAccess.Client"/>

这是代码:

 ConnectionStringSettings ConnectString = ConfigurationManager.ConnectionStrings["default"];
            _dbFact = DbProviderFactories.GetFactory(ConnectString.ProviderName);
            _con = _dbFact.CreateConnection();
            _con.ConnectionString = ConnectString.ConnectionString;
            using (_con)
            {
                _con.Open();
                using (_cmd = _con.CreateCommand())
                {
                    _cmd.CommandText = "select * from EMP;";
                    using (IDataReader reader = _cmd.ExecuteReader())
                    {
                        res = reader.GetString(1);
                    }
                }
                _con.Close();

                MessageBox.Show(res);
            }

我必须使用 DbProviderFactory 因为它必须是不同类型数据库的通用解决方案

4

0 回答 0