如何从odbc获取主机名和端口
how to get hostname and port from odbc
您好,我已经配置了系统 DSN,并且运行良好。所以忘记了主机名地址和端口号,如何通过它找到呢?当我 select 数据源并单击配置时,它只告诉我用户 ID 和 dbalias。我也查看了注册table,只找到这样的东西
" Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\BUS]
"Driver"="C:\PROGRA~1\IBM\SQLLIB\BIN\DB2CLIO.DLL"
"""
DB2 数据库连接由计算机上的 DB2 客户端软件配置。在客户端软件中定义连接后,它们就会暴露给 ODBC 数据源面板。您无法通过控制面板配置它们。
要查看它们,请打开 DB2 命令 Window,然后发出命令 db2 list db directory
。这将列出您的系统知道的所有数据库:
C:\Program Files\IBM\SQLLIB\BIN>db2 list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = SAMPLE
Database name = SAMPLE
Node name = DB2AED1
Database release level = 10.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = IBMDSMR
Database name = IBMDSMR
Local database directory = C:
Database release level = 10.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
在上面的示例中,"Directory Entry Type" 表示数据库是否是本地的 ("Indirect"),即您的机器上有 DB2 服务器 运行)或者数据库是否是远程的 ("Remote"),如上面的 SAMPLE
数据库。
要查看 SAMPLE
的连接详细信息,请记下 节点名称 (上例中的 DB2AED1
)并发出 db2 list node directory
命令:
C:\Program Files\IBM\SQLLIB\BIN>db2 list node directory
Node Directory
Number of entries in the directory = 1
Node 1 entry:
Node name = DB2AED1
Comment =
Directory entry type = LOCAL
Protocol = TCPIP
Hostname = mydb2.whosebug.com
Service name = 50000
您可以看到 DB2AED1
在主机 mydb2.whosebug.com
和端口 50000
上。如果出于某种原因 "Service Name" 字段有一个名称,那么您需要在服务文件中查找该名称(Windows 上的 %windir%\system32\drivers\etc\services
,或 Windows 上的 /etc/services
Linux)
" Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\BUS] "Driver"="C:\PROGRA~1\IBM\SQLLIB\BIN\DB2CLIO.DLL"
"""
DB2 数据库连接由计算机上的 DB2 客户端软件配置。在客户端软件中定义连接后,它们就会暴露给 ODBC 数据源面板。您无法通过控制面板配置它们。
要查看它们,请打开 DB2 命令 Window,然后发出命令 db2 list db directory
。这将列出您的系统知道的所有数据库:
C:\Program Files\IBM\SQLLIB\BIN>db2 list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = SAMPLE
Database name = SAMPLE
Node name = DB2AED1
Database release level = 10.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = IBMDSMR
Database name = IBMDSMR
Local database directory = C:
Database release level = 10.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
在上面的示例中,"Directory Entry Type" 表示数据库是否是本地的 ("Indirect"),即您的机器上有 DB2 服务器 运行)或者数据库是否是远程的 ("Remote"),如上面的 SAMPLE
数据库。
要查看 SAMPLE
的连接详细信息,请记下 节点名称 (上例中的 DB2AED1
)并发出 db2 list node directory
命令:
C:\Program Files\IBM\SQLLIB\BIN>db2 list node directory
Node Directory
Number of entries in the directory = 1
Node 1 entry:
Node name = DB2AED1
Comment =
Directory entry type = LOCAL
Protocol = TCPIP
Hostname = mydb2.whosebug.com
Service name = 50000
您可以看到 DB2AED1
在主机 mydb2.whosebug.com
和端口 50000
上。如果出于某种原因 "Service Name" 字段有一个名称,那么您需要在服务文件中查找该名称(Windows 上的 %windir%\system32\drivers\etc\services
,或 Windows 上的 /etc/services
Linux)