通过ASP.NET提供OraOledb.Oracle提供程序

时间:2015-02-17 18:27:03

标签: c# asp.net-mvc oraoledb

问题:为什么我的本地代码可以执行ORAOleDB.Oracle连接,但是当我通过相同的计算机IIS网站运行匿名执行时,我找不到提供程序。

所以我在本地机器上发布一个网站,以连接到不同的数据库。代码可以很好地连接到数据库并返回我解析的错误代码。我只想确保TNS监听器已启动且Oracle Listener未实际登录。

本地:代码通过

推送到IIS:代码失败

但是,当我将代码发布到我的IIS并运行相同的代码时,我得到的是本地计算机上找不到的OraOledb.Oracle提供程序。

当我发布我的网站时,我收到了每个Oracle数据库的以下消息:

The 'OraOLEDB.Oracle' provider is not registered on the local machine.

I have registered the dll:
cd C:\ProgramData\oracle\oracle11g\BIN
regsvr32 OraOLEDB11.dll

安装oracle的文件夹的以下权限

C:\ProgramData\oracle has the following users:
IIS AppPool\DefaultAppPool
IIS_IUSRS
IIS AppPool\ASP.NET v4.0
All these users have Full Control

我的守则如下。非常简单,它只需要获取数据库名称并生成一个虚拟字符串。

   private void ExecuteDatabase(string database)
    {
        string openstring = "Provider=OraOLEDB.Oracle;Data Source=" + database + ";User Id=x_dummy;Password=x_dummy;Connection Timeout=5;";
        string msg = String.Empty;
        string Elapsed = String.Empty;
        string Result = String.Empty;

        using (OleDbConnection connection = new OleDbConnection(openstring))
        {
            //Timestamp for elapsed time counting
            DateTime stTime = DateTime.Now;
            try
            {
                // Try to connect. If succeed, then close, and create
                // an OK message. x_dummy user and password is improbabile.
                // If connection not successfull, there issued an Oracle
                // exception. We need to parse the exception.
                //connection.ConnectionTimeout = 5;
                System.Diagnostics.Debug.WriteLine("Connection Open");
                connection.Open();
                System.Diagnostics.Debug.WriteLine("Connection Opened");
                // If succeeded...
                msg = "OK";
                //.. then closes
                connection.Close();

            }
            // If connection is not succesfull, we get the errormessage.
            catch (Exception ex)
            {
                //We need the first part of message, this is an Oracle message like this: ORA-01017
                //msg = ex.Message.Split(':')[0];
                msg = ex.Message;
            }
            //Timestamp for elapsed time counting
            DateTime etTime = DateTime.Now;

            //Calculate the elapsed time
            TimeSpan ts = etTime - stTime;

            //Get the millisecs from elapsed time
            Elapsed = ts.Milliseconds.ToString();

            //Get the Result String
            Result = "{" + databaseResult(msg.Split(':')[0]) + "}";
            Result = Result + msg;

        }
    }

    private String databaseResult(string msg)
    {
        string ret = String.Empty;

        switch (msg)
        {
            //kind os listener answers 
            case "ORA-12154":
                ret = "No Oracle listener found";
                break;
            case "ORA-12514":
                ret = "No TNS listener found";
                break;
            case "ORA-12541":
                ret = "No listener ";
                break;
            //ORA-01017 is only good response for us. It means
            //that listener is good, but username and passwor is not.
            //This procedure gives back OK message and elapsed time in this case
            case "ORA-01017":
                ret = String.Format("OK");
                break;
            case "OK":
                ret = String.Format("OK");
                break;
            //In default case this procedure doesn't found listener.
            default:
                ret = "No Oracle listener found";
                break;
        }
        //returns the result of connection                        
        return ret;
    }

0 个答案:

没有答案