数据库在pgadmin中可见,但对于其他程序不存在(Database visible in pgadmin but does not exist for other program)

编程入门 行业动态 更新时间:2024-10-28 16:30:21
数据库在pgadmin中可见,但对于其他程序不存在(Database visible in pgadmin but does not exist for other program)

我使用以下代码在postgresql中创建数据库。

Dim s1 As String s1 = "Provider=MSDASQL;Driver={PostgreSQL ANSI};SERVER=localhost;DATABASE=postgres;UID=username;PWD=pwd;CONNSETTINGS=SET Datestyle TO 'DMY'%3b;BOOLSASCHAR=0;TEXTASLONGVARCHAR=1;TrueIsMinus1=1;" Dim c1 As New ADODB.Connection c1.Open s1 Dim sDB_Name As String sDB_Name = "db1" s1 = "CREATE DATABASE "" " & sDB_Name & """" s1 = s1 & " With OWNER = postgres " s1 = s1 & " TEMPLATE = template0 " s1 = s1 & " ENCODING = 'WIN1252' " s1 = s1 & " TABLESPACE = pg_default " s1 = s1 & " LC_COLLATE = 'English_United States.1252' " s1 = s1 & " LC_CTYPE = 'English_United States.1252' " s1 = s1 & " CONNECTION LIMIT = -1; " c1.Execute s1 MsgBox "done" Unload Me

它运作成功,因为使用pgadmin我可以看到这个新数据库并与之交互。

但是当我尝试通过ADO从创建数据库的程序或其他程序使用此数据库时,我收到消息:

运行时错误'-2147467259(80004005)':致命:数据库“db1”不存在

如果我使用pgadmin创建具有所有相同属性的相同数据库,那么我不会收到此消息,并且可以使用外部程序使用数据库。

有人可以解释一下我做错了什么吗? 谢谢。

I used the following code to create a database in postgresql.

Dim s1 As String s1 = "Provider=MSDASQL;Driver={PostgreSQL ANSI};SERVER=localhost;DATABASE=postgres;UID=username;PWD=pwd;CONNSETTINGS=SET Datestyle TO 'DMY'%3b;BOOLSASCHAR=0;TEXTASLONGVARCHAR=1;TrueIsMinus1=1;" Dim c1 As New ADODB.Connection c1.Open s1 Dim sDB_Name As String sDB_Name = "db1" s1 = "CREATE DATABASE "" " & sDB_Name & """" s1 = s1 & " With OWNER = postgres " s1 = s1 & " TEMPLATE = template0 " s1 = s1 & " ENCODING = 'WIN1252' " s1 = s1 & " TABLESPACE = pg_default " s1 = s1 & " LC_COLLATE = 'English_United States.1252' " s1 = s1 & " LC_CTYPE = 'English_United States.1252' " s1 = s1 & " CONNECTION LIMIT = -1; " c1.Execute s1 MsgBox "done" Unload Me

It worked successfully insofar that with using pgadmin I can see and interact with this new database.

But when I try to work with this database via ADO from either the program that created the database or another program, I get the message :

Run-time error '-2147467259 (80004005)': FATAL: database "db1" does not exist

If I create the same database with all the same properties using pgadmin then I don't get this message and can work with the database using external programs.

Can somebody please explain what am I doing wrong? Thank you.

最满意答案

我做错了是因为我正在创建一个名为的数据库

“db1”

而不是

“DB1”

(名称中有一个领先的空间)。

代码中的这一行是错误的:

s1 = "CREATE DATABASE "" " & sDB_Name & """"

应该是的

s1 = "CREATE DATABASE """ & sDB_Name & """"

What I was doing wrong was that I was creating a database called

" db1"

rather than

"db1"

(there's a leading space in the name).

This line in the code was wrong :

s1 = "CREATE DATABASE "" " & sDB_Name & """"

It should have been

s1 = "CREATE DATABASE """ & sDB_Name & """"

更多推荐

本文发布于:2023-08-07 18:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465907.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   但对   于其   数据库   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!