SQL Server connection string with "$" in password - powershell

I have a connection string to a SQL Server 2012 DB:
$CONN_STR = "Server=SERVER;Database=mydb;User ID=myuser;Password=abc1$4def;"
I'm creating a connection in PowerShell, but the login fails due to invalid password. I know that the password is correct and validated that in SSMS. I've tested with another account and from what I can tell, the special character in the password is causing the failure.
How can I escape this in the connection string that I use in PowerShell?

try this:
$CONN_STR = 'Server=SERVER;Database=mydb;User ID=myuser;Password=abc1$4def;'
Use single quotes instead that way it wont think you are trying to reference a variable

Related

How to deal with an '#' symbol in postgres password [duplicate]

Using a Postgresql URL connection string in the format of:
postgresql://user:secret#localhost
How do I handle special characters in that string (e.g., $) so that it will actually function when I connect to my postgres database?
I've tried simply URL encoding it, so for example, "test$" becomes "test%24" ... but that seems to be a problem as I get a "FATAL: password authentication failed " error when attempting to use it.
See Connection URIs in the doc.
There are a few things that don't seem quite right in your question:
URIs are supported by postgres since version 9.2 only, so with a 9.1 client that's not supposed to work at all. Or you're using a client that implements connection URIs itself.
Percent-sign encoding is supported. Per doc:
Percent-encoding may be used to include symbols with special meaning
in any of the URI parts.
Percent-encoding is not even necessary for a dollar character.
Tried with 9.3:
sql> alter user daniel password 'p$ass';
$ psql 'postgresql://daniel:p$ass#localhost/test'
works
$ psql 'postgresql://daniel:p%24ass#localhost'
works
psql 'postgresql://daniel:pass#localhost/test'
fails as expected: bad password.
Maybe your input shell has a different encoding and $ is not %24.
Check it out on https://www.urlencoder.org/
Hint:
If you use alter user "username" password 'p$ass''word' to set/change the password,
single quotes have to be masked with another singlequote.

dblink from remote server into a Google Cloud SQL instance using .pgpass

I'm trying to connect to a Google Cloud SQL instance using dblink, which works well when setting up my username and password in the connection string, but I would like to save my Client credentials in the SQL instance not to have the need to explicitly put my password in the connection.
The .pgpass file which will used is the one that belongs to the OS user which is running the local database ('~/postgres/.pgpass', in most cases). And then for security reasons, it works only if you are locally a superuser. Can you meet those criteria?
but I would like to save my Client credentials in the SQL instance
What does "SQL instance" mean? I would not think that .pgpass would count as being inside the SQL instance.
An alternative solution is create a foreign server with "postgres_fdw". This doesn't seem to be documented (edit: it is documented here, but uses dblink_fdw not postgresql_fdw), but you can pass the name of a "postgres_fdw" foreign server (in single quotes) to dblink functions as the connection string. It will then pull the password to be used from the USER MAPPING for that server and user. I would think the USER MAPPING counts as inside the "SQL instance".

Solr database configuration: password with special characters

I'm trying to configure Solr to connect to a postgresql database. The problem is, the password contains special characters.
]T&FV{)pO-#lpMdD (this is an example of what am trying to use as password)
I tried escaping these characters with \ but it's not working.
I also tried with http encoding %5DT%26FV%7B%29pO-%40lpMdD but it's not working either.
Solr uses JDBC to connect to your database, so escaping the password would be the same as for regular JDBC strings.
You should be able to wrap your password in quotes - "<password>" - if you're going to use http encoding, it should be supplied at the end of the connection URL (i.e. /database?password=%5DT....

Connection to Azure postgres server fails in spite of correct username

When trying to connect to my postgres server in Azure from psql client, I get the following error, even though I am using the correct username. How can I fix this?
psql: FATAL: Invalid Username specified. Please check the Username and retry connection. The Username should be in <username#hostname> format.
As noted in the error text, you are required to follow the <username#hostname> format when trying to connect to postgresql server, whether you are doing it from psql client or using pgadmin. Using <username#hostname> format instead of just <username> should get rid of the error.
Read the quick-start documents for Azure portal and CLI to understand more about how to create and configure your postgres server.
The # sign in username works fine for objects but not connect strings. According to URI RFC-3986 username allows hex encoding. So replace the # with %40. user#host:pw#fullhost becomes user%40host:pw#fullhost

connectionstring with userid but blank password for ado.net C#

I am not able to connect to the server say for instance from SQL Server Management Studio I am able to connect to the server 192.168.7.3 as server address using SQL Server authentication and also using the user ID as super.
But can someone tell me how to give the connectionstring so that I can use a blank password for the user "super" from the ado.net connectionstring so that I can connect to the server using SqlConnection object something like this :
SqlConnection con = new SqlConnection("server=192.168.7.3;database=test;user ID=super;password=");
I'm trying this but it's not working. What's the actual syntax to use a blank password for the server connection in sqlconnection object?
Note, this is the requirement. I know using blank password isn't recommended, but I am forced to do this.
The following ConnectionString should work. If not, the problem is elsewhere, perhaps network related.
Data Source=192.168.7.3;Initial Catalog=test;User Id=super;Password=;
Reference: SqlConnection.ConnectionString Property