使用Powershell连接到远程PostgreSql数据库 [英] Connect to remote PostgreSql database using Powershell
问题描述
我正在尝试使用Powershell连接到远程PostgreSql数据库.这是我第一次使用Powershell,所以如果这是一个菜鸟问题,我感到很抱歉.这是我的代码:
I'm trying to connect to a remote PostgreSql database using powershell. This is my first time using powershell so I'm sorry if this is a noob question. This is my Code:
$DBConnectionString = "Driver={PostgreSQL UNICODE}:Server=$MyServer;Port=$MyPort;Database=$MyDB;Uid=$MyUid;Pwd=$MyPass;"
$DBConn = New-Object System.Data.Odbc.OdbcConnection;
$DBConn.ConnectionString = $DBConnectionString;
$DBConn.Open();
$DBCmd = $DBConn.CreateCommand();
$DBCmd.CommandText = "SELECT * FROM mytable;";
$DBCmd.ExecuteReader();
$DBConn.Close();
运行此命令时,我收到异常调用打开",参数为"0":错误[IM002] [Microsoft] [ODBC驱动程序管理器]找不到数据源名称,未指定默认驱动程序".我已经下载并安装了pgsqlodbc驱动程序,但是仍然出现此错误.有谁知道如何解决这个问题?我已经搜索了互联网,但现在我真的什么也没找到.
When I run this I get "Exception Calling "Open" with "0" argument(s): ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified". I've downloaded and installed the pgsqlodbc driver but I'm still getting this error. Does anyone have any ideas how I could fix this? I have searched the internet and I'm really not getting anywhere at this point.
谢谢.
推荐答案
检查DSN是否存在于ODBC数据源中.如果不是,则必须创建一个转到控制面板",管理员"的文件夹.工具",数据源(ODBC)".然后选择添加用户DSN"- 选择PostgreSQL驱动程序,然后填写您的服务器和数据库详细信息. 测试连接检查就可以了!
Check if the DSN exists in ODBC data source. If not you have to create one going to 'Control Panel', 'Admin. Tools', 'Data Sources (ODBC)'. Then select 'Add User DSN'- Select the PostgreSQL driver, and fill in your server and database details. Test connection to check is all ok!
这篇关于使用Powershell连接到远程PostgreSql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!