dongya8378
dongya8378
2019-06-04 00:54
浏览 208

找不到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.

图片转代码服务由CSDN问答提供 功能建议

我有一个用Go语言编写的访问Oracle数据库的服务器。 工作正常。 但是,将有多个实例在不同的位置(当前为2个)运行,其中一些实例不需要访问数据库。 (他们从对等服务器获得传递给他们的相同信息。)

我希望在所有地方都运行相同的可执行文件,但是有些文件将被配置为不使用数据库,因为它们不会 不需要它。 问题是,一旦导入OCI程序包,它的init()函数就会被调用,当它无法与数据库对话时会发生恐慌。

在Windows Server 2019上运行GO 1.12.5

我尝试将OCI.DLL添加到与.EXE相同的目录中,但仍然会出现问题。

  import _“ github。  com / mattn / go-oci8“ 
   
 
 

当我在服务器上运行(没有DB驱动程序)时,出现错误: < pre> 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

当我不需要数据库访问权限时,我想避免这种恐慌。 我希望一个.EXE不会有条件构建的混乱情况。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • drt12345678
    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.

    点赞 评论
  • douyun3887
    douyun3887 2019-06-04 02:34

    As you said, adding the DLLs to the same directory as the exe solves your problem, so if you wanted a single file to still work you can have the exe copy all of the DLLs over when it starts, and even delete then when it is done if you want. This way, you can transfer the file to multiple locations, but there is most likely no way to keep it one file while running.

    点赞 评论

相关推荐