0

我正在使用 System.data.oracleclient 命名空间并将该 dll 放在我的项目的引用中

我使用连接字符串作为

SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xx.x.xxx)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xxxx)));uid=xxxx;pwd=xxxx;

在运行应用程序时,我收到响应消息

OCIEnvCreate failed with return code -1 but error message text was not available.

我不知道我卡在哪里了......

谁能给我任何指导方针来解决这个问题。

我也护目镜,但没有得到正确的解决方案。

等待您的宝贵建议和意见

更新 1:

我使用的代码是

   con = new OracleConnection(conStr);
                con.Open(); // connection must be openned for command
                query = "insert into table1 values ('ss');
                cmd = new OracleCommand(query, con);
               if(cmd.ExecuteNonQuery()>0)
                {
                    Console.WriteLine("insert sucess!");
                }
                con.Close();

我的堆栈跟踪错误是

   at System.Data.OracleClient.OciHandle..ctor(OciHandle parentHandle, HTYPE handleType, MODE ocimode, HANDLEFLAG handleflags)
   at System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(String userName, String password, String serverName, Boolean integratedSecurity, Boolean unicode, Boolean omitOracleConnectionName)
   at System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions)
   at System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OracleClient.OracleConnection.Open()
   at oracleTest.Program.getconnection() in D:\oracle\oracletst[via-oracleclient]\oracletst\Program.cs:line 29
   at oracleTest.Program.Main(String[] args) in D:\oracle\oracletst[via-oracleclient]\oracletst\Program.cs:line 21
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
4

1 回答 1

0

我看到的两件事可能会导致问题

  1. 您没有处理 ado.net 对象
  2. con&cmd似乎是一个共享变量。

试试这个,看看问题是否仍然存在。

using(var con = new OracleConnection(conStr))
using(var cmd = con.CreateCommand())
{
    con.Open(); 
    cmd.CommandText = "insert into table1 values ('ss');
    if(cmd.ExecuteNonQuery() > 0)
    {
        Console.WriteLine("insert sucess!");
    }
}

因为我们使用了using关键字,所以当块退出时它会自动调用 con/cmd.Dispose() 。Dispose() 将自动调用 Close()。

编辑 确保您的连接字符串格式正确。http://www.connectionstrings.com/oracle

于 2012-09-17T13:05:46.873 回答