dongya8378 2019-06-04 00:54
浏览 369
已采纳

找不到Oracle数据库客户端库时避免陷入恐慌

I have a server written in Go that accesses an Oracle database. It works fine. However, there will be multiple instances running at different (currently 2) locations some of which do not need to access the database. (They get the same info passed on to them from their peer servers.)

I want the same executable running in all places but some will be configured to not use the database since they don't need it. The problem is that once I import the OCI package, its init() function is called which panics when it can't talk to the database.

Running GO 1.12.5 on Windows Server 2019.

I tried adding OCI.DLL to the same directory as the .EXE but it still panics.

import _ "github.com/mattn/go-oci8"

When I run on the server (without DB drivers) I get the error:

panic: OCIEnvCreate error

goroutine 1 [running]:
github.com/mattn/go-oci8.init.0()
        D:/Golang/src/github.com/mattn/go-oci8/globals.go:160 +0x130

I want to avoid this panic when I don't need database access. I would prefer one .EXE without the mess of conditional builds.

  • 写回答

2条回答 默认 最新

  • drt12345678 2019-06-05 23:02
    关注

    Swap to the Go goracle driver which delays Oracle client library initialization until connections are opened precisely to handle your situation, where not all app users connect to Oracle DB.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试