无法从c#表单应用程序建立oracle连接

时间:2016-12-19 10:11:31

标签: c# oracle

我试图将两个参数传递给我的oracle包。

我可以获取参数,但它没有被传递到数据库中。每次运行应用程序时,它都无法建立连接并直接进入我的try catch方法。

我做错了吗?

这是我到目前为止所做的:

using System.Data.OracleClient;

private void btnGetData_Click(object sender, EventArgs e)
{
    GetOrders_OracleCon_GetData(Parameter1,Parameter2);
   // when i output or add in a break i can see that the data does come into the Parameter values. However after that it doesnt go to my db
}

public void GetOrders_OracleCon_GetData(Int32 PM1, String PM2)
{
    using (OracleConnection objConn = new OracleConnection("Data Source=" + dbcon + "; User ID=" + uid + "; Password=" + pass))
    {
        OracleCommand objCmd = new OracleCommand();

        objCmd.Connection = objConn;

        objCmd.CommandText = "PCK_Orders.get_data";

        objCmd.CommandType = CommandType.StoredProcedure;

        objCmd.Parameters.Add("pm1", OracleType.Number).Value = PM1;

        objCmd.Parameters.Add("pm2", OracleType.VarChar).Value =PM2;

        objCmd.Parameters.Add("selected_orders", OracleType.Cursor).Direction = ParameterDirection.Output;

        try
        {                    
            objConn.Open();

            OracleDataReader objReader = objCmd.ExecuteReader();

            if (objReader.HasRows)
            {                        
                GetOrders_GetData(objReader);
                btnCancel.Enabled = true;
            }
            else
            {
                Timer_ProgBar.Stop();

                MessageBox.Show("Orders for this Datedoes not exist", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                GP_ClearAllFields("Y", "Y");

                Timer_ProgBar_Initialize(0, "");
            }
        }
        catch (Exception)
        {
            Timer_ProgBar.Stop();

            MessageBox.Show("An error has occured");
              // this is the error that i catch but im not sure what is causing it. am i missing something?                  
            Timer_ProgBar_Initialize(0, "");
        }

        objConn.Close();
    }
}

0 个答案:

没有答案