Create Databse in Windows from command-line or VBScript? - database

How to create a new database for PostgreSQL 10 (pgAdmin 4) from command-line or VBScript in Windows?
I used the following command from command-line:
pg_dump --dbname=postgresql://postgres:123#localhost:5432/myDB --format=p --clean
But it returned the following error:
pg_dump: [archiver (db)] connection to database "myDB" failed: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
How to run the server in "localhost" (127.0.0.1)? How to fix this?
EDIT:
Furthermore, I also tried this,
createdb --dbname=postgresql://postgres:123#localhost:5432/myDB --format=p --clean
And got this error,
createdb: illegal option --
dbname=postgresql://postgres:123#localhost:5432/myDB
Try "createdb --help" for more information.

I found the solution at here thanks to Jasen and Mladen Uzelac. This is the command-line to create the database,
cd "C:\Program Files (x86)\PostgreSQL\10\bin"
psql -c "CREATE DATABASE mydb" "user=postgres dbname=postgres password=something_secret"

Related

Cannot connect to custom SQL Server docker image

we're currently using Windows containers and, as there are no official SQL Server images for Windows, we are building our own.
We've successfully created the image and by running via
docker run --name SQLServer2022preview -e ACCEPT_EULA=Y -e sa_password=PaSSw0rd -p 1433:1433 -d mycompany:winsrv1809-sql2022preview
I can connect and work as expected to localhost,1433. However, this image will act as a base and we need to build another image based on this on runtime. When doing so, is where it can't connect. We're getting this message
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [2]. .
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; sqlcmd -i "C:\restore.sql"' returned a non-zero code: 1
This is the docker file
FROM mycompany:winsrv1809-sql2022preview
EXPOSE 1433
EXPOSE 4338
COPY ./databases/DB1.bak C:/
COPY ./HAS_Database/restore.sql C:/
RUN sqlcmd -i "C:\\restore.sql"
and restore.sql
RESTORE DATABASE DB1
FROM DISK = N'C:\DB1.bak'
WITH FILE = 1,
MOVE N'DB1_Imported'
TO N'C:\DB1.mdf',
MOVE N'DB1_log'
TO N'C:\DB1_log.ldf',
NOUNLOAD,
STATS = 5;
GO
There's no login errors in sql log looking into the container (which automatically closes after aprox 30 sec) so I guess that it may be relative to port forwarding. Can anyone help?
I tried port forwarding in the start step, with no luck. I'm a docker newbie

Unable to connect SQL Server with ODBC drivers on linux

I have install the driver odbc 2.3.0 on linux by this reference: https://www.microsoft.com/en-ca/download/confirmation.aspx?id=28160
All these steps work correctly.
This is my configation:
SERVER:
Oracle server is on linux
SQL Server is on windows
SQL Server:
My login and password are the same. It's: demo
When I use cmd and I use the command: "ipconfig", I can get my IP
My IP is: 192.168.0.106
This is how I do my connection manually and it work:
After the installation, i have configure my files odbinst.ini and odbc.ini
This is my file odbcinst.ini:
This is my file odbc.ini:
This is where my driver is download:
My instance name is MSSQLSERVER and TCP-IP and listen all are enable:
Dynamic port is blank and static port is 1433:
As you see, I can be connect on localhost with the command line:
sqlcmd -S 192.168.0.106 -d demo -U demo -P demo
But, I can't connect with my Oracle server on putty with this command line:
isql MSSQLSERVER -v
Why it don't work?
The server is start
Allows remotely connexion is enable
I have add port 1433 in firewall setting
I tried to disable the firewall, nothing change
Something is wrong in my configuration?
Problem reseolve :
Change sqlServer Localhost to SqlServer.
You can't connect 2 server if they are on localhost. You need an oracle SQL Server and SQlServer working not on LocalHost

Azure Data Studio-server connection error on Mac bookpro

To run SQL Server on my Mac, I installed Docker and SQL Server Management Studio (Azure Data Studio) and got connected to the server. However, when I tried to reconnect another time, I got the error below. I've found much advice about how to fix the issue on Windows, but not on Mac.
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: TCP
Provider, error: 40 - Could not open a connection to SQL Server)
Increase Docker memory from 2 GB to 4 Gb from Preferences then again run the following commands,
docker pull microsoft/mssql-server-linux:2017-latest
Now, launch an instance of the Docker image.
docker run -d --name name_your_container -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=P#55w0rd' -e 'MSSQL_PID=Developer' -p 1433:1433 microsoft/mssql-server-linux:2017-latest

Connect host machine's SQL Server 2017 from homestead vagrant

I'm trying to connect my local/host machine SQL Server from Laravel vagrant homestead. I've been googling all day trying to connect the host machine's database installing different PHP packages but so far have no lucks. I thought I would remove PHP at this point and try to establish the connection inside homestead using sqlcmd instead.
So, I have installed sqlcmd in homestead and tried to execute the following command to connect to the host machine's database.
sqlcmd -S 10.0.2.2,1433 -U sa -P 'password' -Q "sp_databases"
However, I received the following error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection because an error was encountered during handshakes before login. Common causes include client attempting to connect to an unsupported version of SQL Server, server too busy to accept new connections or a resource limitation (memory or maximum allowed connections) on the server..
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2746.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection due to prelogin failure.
However, If I use sqlcmd on my host machine and execute the following command, I am able to access the database.
sqlcmd -S LAPTOP-ACQES\MSSQL2017 -U sa -P Asdf1234 -Q "sp_databases"
In my Homestead.yaml, I have set up port forwarding from:
ports:
- send: 1433
to: 1433
You say this doesn't work:
sqlcmd -S 10.0.2.2,1433 -U sa -P 'password' -Q "sp_databases"
Yet this does:
sqlcmd -S LAPTOP-ACQES\MSSQL2017 -U sa -P Asdf1234 -Q "sp_databases"
In the former, you are using the IP, but no instance name.
Try:
sqlcmd -S 10.0.2.2\MSSQL2017 -U sa -P 'password' -Q "sp_databases"
Also:
Ensure TCP/IP is enabled in SQL Network Configuration.
Verify SQL Server Browser is running.
Allow remote connections in SQL Server properties.
Lock SQL Network configuration to port 1433 on all adapters, and disable dynamic ports (then restart services).

Unable to connect to postgres database through heroku

I have a postgres database that I created through heroku. I am trying to access it through psql with the command:
cse-190-fortune matanvardi$ psql "dbname=dccemfsa6camml host=ec2-54-235-152-226.compute-1.amazonaws.com \
user=tfmfbqxqjznsbl password=********* port=5432 sslmode=require"
I get this error:
psql: could not connect to server: Operation timed out
Is the server running on host "ec2-54-235-152-226.compute-1.amazonaws.com" and accepting
TCP/IP connections on port 5432?
I've cloned the repository and I'm logged in, I simply cannot figure out what is wrong here. Any help would be greatly appreciated.
To access your Heroku database from the command line use the command:
heroku pg:psql
Edit:
I ran your command from my machine. If course I don't have your password but I got:
$ psql "dbname=dccemfsa6camml host=ec2-54-235-152-226.compute-1.amazonaws.com user=tfmfbqxqjznsbl port=5432 sslmode=require"
Password:
psql: FATAL: password authentication failed for user "tfmfbqxqjznsbl"
Which means I was able to connect, which is farther than you got. It must be a problem with your network setup.

Resources