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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化