Geeks,. I want to execute the SQL queries below by a script in powershell ISE. This is a sql function already written
select UserAndRoleInsert('test@email.com','VesselName','Master','Vessel Master'); select ClientInsert();
How can I connect with postgres sever using powershell code? server is 'test123' Database is 'IdentityAdmin_Shore' In localhost
You can try below:
Install Postgresql ODBC driver
.
Make sure your system recognizes the driver. For example, if your system is Windows then add DSN in the ODBC Datasource Admin
.
3. Then try executing the code(Though I haven't tested it from my end). You can store the user id and password in a config file.
$DBConnectionString = "Driver={PostgreSQL Unicode(x64)}:Server=<server>;Port=<port>;Database=$MyDB;Uid=<userid>;Pwd=<pass>;" $DBConn = New-Object System.Data.Odbc.OdbcConnection; $DBConn.ConnectionString = $DBConnectionString; $DBConn.Open(); $DBCmd = $DBConn.CreateCommand(); $DBCmd.CommandText = "<query1>;<query2>;"; $DBCmd.ExecuteReader(); $DBConn.Close();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.