[英]Postgresql odbc driver error c# [IM002] [Microsoft][ODBC Driver Manager] Data source name not found
I am setting up an database application to be database agnostic, and when testing with postgresql I get the standard dsn error: 我正在将数据库应用程序设置为与数据库无关,并且在使用PostgreSQL测试时,我收到标准的dsn错误:
[IM002] [Microsoft][ODBC Driver Manager] Data source name not found
[IM002] [Microsoft] [ODBC驱动程序管理器]找不到数据源名称
I usually use SQL server and MySQL so I'm new to postgres, I tried the standard recommended Connection string: 我通常使用SQL Server和MySQL,因此对Postgres并不陌生,我尝试了推荐的标准连接字符串:
"Driver = {PostgreSQL}; Server = localhost; Database = postgres; Port = 5432; Uid = postgres; Pwd = XXXXXX;"
I also tried the name of the odbc driver that I installed after installing postrgesql: 我还尝试了在安装postrgesql之后安装的odbc驱动程序的名称:
"Driver = {PostgreSQL ODBC Driver(UNICODE)}; Server = localhost; Database = postgres; Port = 5432; Uid = postgres; Pwd = XXXXXX;"
Setting up a DSN in odbc manager also works perfectly using the unicode driver, so I cant understand why i cant connect in my application, is there an error in the driver name that i am using in the connection string? 在odbc管理器中设置DSN也可以使用unicode驱动程序完美地工作,因此我无法理解为什么我无法在应用程序中进行连接,我在连接字符串中使用的驱动程序名称是否存在错误?
Your error message looks very strange. 您的错误消息看起来很奇怪。 It tells about DSN not found.
它说明未找到DSN。 Are you sure you use connect string with
Driver=...
? 您确定使用
Driver=...
连接字符串吗?
You can use ODBC connect string in several forms. 您可以以多种形式使用ODBC连接字符串。 At first you have created DSN, so you can use it:
首先,您已经创建了DSN,因此可以使用它:
DSN=mn_test; Uid=postgres; Pwd=postgres;
Then you can use other form of connect string: 然后,您可以使用其他形式的连接字符串:
Driver={PostgreSQL UNICODE};Server=127.0.0.1; Port=5493; Database=mn_test; Uid=postgres; Pwd=postgres;
Both work on my old 32 bit Windows environment. 两者都可以在我的旧32位Windows环境下工作。 I test them with simple Python script (I use ActiveState Python in which there is simple
odbc
module): 我用简单的Python脚本测试它们(我使用ActiveState Python,其中有简单的
odbc
模块):
import odbc
def test_odbc(connect_string):
print(connect_string)
db = odbc.odbc(connect_string)
c = db.cursor()
rs = c.execute("SELECT version()")
for txt in c.fetchall():
print('%s' % (txt[0]))
print('-----')
test_odbc('Driver={PostgreSQL UNICODE};Server=127.0.0.1; Port=5493; Database=mn_test; Uid=postgres; Pwd=postgres;')
test_odbc('DSN=mn_test; Uid=postgres; Pwd=postgres;')
When you created the DSN, did you create it with the correct odbcad tool? 创建DSN时,是否使用正确的odbcad工具创建了DSN? With the 64bit version found in
C:\\Windows\\System32
if your application is 64bit and with the 32bit version found in C:\\Windows\\SysWOW64
if your application is 32bit? 如果您的应用程序是64位,则在
C:\\Windows\\System32
找到64位版本;如果您的应用程序是32位,则在C:\\Windows\\SysWOW64
找到32位版本?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.