Error 28P01 - Password authentication failed - c#

recently I have started my adventure with databases.
I have managed to install postgreSQL and create simple database.
I've tried to create simple app which will allow me to view data from DB.
I'm using VS 2017. I have managed to configure DataSource in my WindowsForm (NetFramework) project. Test connection was successful.
When I try to fill my ListBox with data from table I'm recieving error 28P01 (it seems to mean that I'm using wrong password / username).
It is impossible - im using default account (postgres) and passsword which allowed me to populate DB in datagrip.
Can anyone help me to understand what is going on?

Guys I have managed to work it out. The thing that I did bad was configuration of connection in VS DataSource configuration. I had choosen NOT to include sensitive data into connection string - I had to put it in my code or change setting to INCLUDE it.
I feel so dumb

Related

C# Executing a query and getting data out of an Access Database (accdb) without using ACE.OLEDB

I'm writing a WPF application.
Trying to use the normal method of getting a connection returns an error similar to: "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine."
ACE.OLEDB has never been installed on this machine so this error makes sense.
I'm trying to create this application in a way so that our users won't need to contact IT to have the application installed. Getting IT involved is a no go situation and the project will be abandoned.
Another team has an Access database (accdb) that I want my application to extract information (only read, no insert or update). I talked to the team and they won't convert this database back to an earlier version (mdb).
After my research I assume that installing ACE.OLEDB without using Admin privileges is impossible. Because of this and my application requirement of not requiring admin privileges I need to start looking for "Mutant"/Dirty solutions that don't involve ACE.OLEDB.
I tried using power-shell but I'm getting the same problems as I had with C# (requires IT to install ACE.OLEDB).
I have two potential solutions. One write a VBA script that opens up the database and dumps a query result into a file. My C# application would call this VB script and then parse the created file.
The second option is to create a new Access process using Process.Start(fullFilePath) and somehow pass the command to execute a query and somehow pass the results back to the executing application (either via a method return or first to a file).
How would you get the data out?
Is there a way for C# to duplicate the DB file and convert it from (accdb -> mdb)?
This is the second question I ask that is very similar.
C# Connecting to Access DB with no install
The difference between the two (to prevent this is a duplicate question) is that in the previous question I was looking for ways to install ACE.OLEDB without admin privileges while here I'm just looking for any other work around.
Found a workaround. It uses Microsoft.Office.Interop.Access found in NuGet.
var accApp = new Microsoft.Office.Interop.Access.Application();
accApp.OpenCurrentDatabase(#tests.DatabasePath);
Microsoft.Office.Interop.Access.Dao.Database cdb = accApp.CurrentDb();
Microsoft.Office.Interop.Access.Dao.Recordset rst =
cdb.OpenRecordset(
"SELECT * FROM Users",
Microsoft.Office.Interop.Access.Dao.RecordsetTypeEnum.dbOpenSnapshot);
while (!rst.EOF)
{
Console.WriteLine(rst.Fields["username"].Value);
rst.MoveNext();
}
rst.Close();
accApp.CloseCurrentDatabase();
accApp.Quit();

Entity Framework - Database first - Intercepting DbContext

I am developing a Web API that uses Entity Framework 6. The Connection String for Entity Framework is encrypted with a company standard encryption. (sql server 2014) I can decrypt the connection string just fine, but I have not been able to figure out how to intercept DbContext to set the decrypted connection string. (Before the Web.config had an encrypted connection string, I was able to run the API just fine, and all database calls works appropriately)
The code below shows how I have circumvented the issue thus far. I have created a partial class for my context class, since the Peliquin.Context.cs class is generated code. I am decrypting the connection string, which as I've verified, looks exactly correct, then passing it into this class. The previous code was :base("name=ConnectionName")
The error message seems as if DbContext cannot have an actual connection string passed into it. But if I pass in the connection name, it runs into an issue with the connection string being encrypted.
I have searched and have been unable to find the solution to this seemingly simple problem. Any help would be appreciated.
The web.config connection string, before I decrypt it at runtime:
Side note: This website will get deployed to several client sites, each that have their own database credentials. At the time of the installer installing the API and UI web applications onto the server, another application runs that updates the web.config file to the proper client database connection. This entire process is to have no user interaction. If anybody can think of a better method of changing the web.config connection string, then encrypting it, all without human interaction, please feel free to suggest an alternate solution to me.
Well, I seemingly fixed the problem myself. In the dynamically generated code Peliquin.Context.cs, I pass in the decrypted connection string, and it all works fine. What I don't like about this solution, is that the next time the edmx file is updated with the latest database changes, this file will dynamically be generated again, wiping out my changes, which will cause havoc in the future. Having another class take the constructor, still seems like a better solution.
public PeliquinDbContext(string connection):base(connection)
{
}

Access denied for user 'root'#'localhost' (using password: YES) in Visual Studio

Kindly bear with me. I am a Microsoft SQL Server person with loads of Visual Studio experience, but I need to get something done using a MySQL database.
I am trying to create a little tool here that will allow our developers to quickly update database records, and I am using Visual Studio to create a small Windows Form to do this.
In a Microsoft SQL Server connection string, I could write something like this:
Server=myServerAddress;Database=myDataBase;User Id=username;Password=password;
In a MySQL connection string, there appear to be multiple other options, but the first one looks basically the same:
Server=myServerAddress;Database=myDataBase;Uid=username;Pwd=password;
When I attempt to open the MySQL connection from my PC, I get the exception listed in the title (actually, it shows the Uid value and the IP Address of my PC instead of localhost, but I am hoping more people will recognize the error easier this way):
public static void MySQLi_Connect() {
m_err = null;
var str = Properties.Settings.Default.ConnStr;
try {
m_conn = new MySqlConnection(Properties.Settings.Default.ConnStr);
m_conn.Open();
} catch (MySqlException err) {
ErrorLog("MySQLi_Connect", err);
}
}
I did a search, and it seems that the Uid on MySQL needs to be granted access from the specific IP Address that the connection is being made from.
Further, I found this on the mysql.com doc pages:
If you do not know the IP address or host name of the machine from which you are connecting, you should put a row with '%' as the Host column value in the user table. After trying to connect from the client machine, use a SELECT USER() query to see how you really did connect. Then change the '%' in the user table row to the actual host name that shows up in the log. Otherwise, your system is left insecure because it permits connections from any host for the given user name.
A few things:
It looks like I can connect to MySQL by using a % setting in the Uid jp2code, but MySQL says I need to change that back right away to remove system vulnerability.
Microsoft SQL Server did not seem to require this - or, if it did, I simply never was slapped in the face with this vulnerability issue like MySQL is doing.
Now, I ask:
If this is going to be a tool used by different developers on different PCs, is it common practice to turn the blind eye to this horrendous system vulnerability?
Is this not really as big of a concern as MySQL is making it appear?
What is the best way to continue with a Windows Forms application that needs to connect from various locations? Obviously, I do not want to continuously be adding more entries for a particular application every time another developer wants to use the tool or someone tries to run it from a different PC.
You can configure the security of your MySQL server as strong as you like, usually you dont connect users but applications. So if you have your root user without password in production environment is your fault. Usually developers have access to development environment, so this is not a big deal.
Of course try to have as many users as roles you need, for your example I think one user is enough. In production use a secure config file for save a secure password and set you mysqlserver restricted.
I was having the same issue and I found out that the password wasn't correct.
GO to your sql command line and type the code below:
mydb in the line below is the name of the database you are working on.
passwd in the line has to match the password you have in c# code so in your case "password"
grant all privileges on mydb.* to myuser#localhost identified by 'passwd';
Like OP says you can wildcard the hostname portion. I used this on our dev-server (not recommended for production servers):
update mysql.user set host = '%' where host='localhost';
Then I had to restart the server to make MySQL use it (propably I could just have restarted the MySQL service).

Authentication with old password no longer supported, use 4.1 style passwords

I have my website with hostgator and I want to access mysql database with C# windows application but when I tried to connect got this message:
"Authentication with old password no longer supported, use 4.1 style
password"
I have tried given solution:
SET SESSION old_passwords=0;
SET PASSWORD FOR user#host=PASSWORD('your pw here');
first query executed successfully but I got the error "Access denied for user#host" when second query executed. I can't understand why there is this problem. I am using MySQL-connecter-net 6.6.5.
I successfully connect my database with MySql workbench 5.2.47.
Can anyone help me what I can do more?
I have contact my hosting site and they make changes to my.cnf file to use 4.1 style password. and i am able to connect with mysql
mysql -u <username> -p <password> -h <hostname>;
but when i tried to connect with C# with mySQL connecter net 6.6.5 i again got this error.
I am using Visual Studio 2012 with MySQL connector 6.6.5 on Windows 8 64 bit. this is the code i used to connect
using MySQL.Data.MySQLClient;
private void button1_Click(object sender, EventArgs e)
{
string connStr = String.Format("server={0};port={1};uid={2};password={3};database={4}",
txtserver.Text, txtPort.Text, txtUser.Text, txtPassword.Text, txtDatabase.Text);
conn = new MySqlConnection(connStr);
try
{
conn.Open();
MessageBox.Show("Test Connection Succeded");
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
I can't understand where the problem is. Please Help me
I had the same problem. In my case just ran the command below connected on my database by the Workbench:
SET SESSION old_passwords=0;
SET PASSWORD FOR my_user=PASSWORD('my_password');
After that I could connnect using MySql Connector 6.6.5 in the c# code with the common mysql connection string:
"server=my_server_ip;user=my_user;database=my_db;port=3306;password=my_password;"
Today I had a similar problem in my C# application. I tried connecting to a server at hostgator.com (mysql) and connecting to localhost. After reading many posts and making many alterations, following every step but I couldn't connect to my hostgator mysql.
The solution in my case was to change the MySql Connector/NET library from version 6.* to version 5.*. After the change my application connected successfully.
While this might not be a viable solution for everyone, it may work for some.
I met this problem today, but I'v fixed it as below:
SET old_passwords=FALSE;
SET PASSWORD = PASSWORD('new pwd here');
Well, maybe the server's connection version is lower than the client, so you have to run this:"SET old_passwords=FALSE;"
Good Luck!
Had the same problem using MySqlClient package for C#. Let's break it down:
We need the database to not use old style passwords, thus we perform
SET old_passwords=0;
NOTICE there is no "SESSION" keyword. This is what allowed only your first query to work, "SESSION" implies temporary and any session settings are lost after a session ends.
Next we need to set the password of the user#host to the new password style
SET PASSWORD FOR user#host = PASSWORD('password');
This two should allow your MySqlClient
Just wanted to add to #diangelisj answer and say the root of the problem is the version of PhpMyAdmin installed on your server. In order to use the latest MySQL Data Connector class, you have to have the latest PhpMyAdmin (or issues arise). In my case, I have PhpMyAdmin 4.0.10.7 and tried using MySQL Data Connector 6.7.9, which gave the error.
What I did:
Download version 5.2.7 from https://dev.mysql.com/downloads/connector/net/6.9.html
Add .dll as reference to application
Presto!
Forget about applying SET old_password=0 since if the server is configured to use new password there is no reason to change the flag on the server if your app does not access anymore. Investigate the connector NET that you are using.
Connector 6.5.4 is the right one to use old_password, rencent version are using the new one.
The best practice would be to avoid to install the connector on the machine, just leave the NET to handle the dll if you already have it or anyway try to find MySQL.Data.DLL version 6.5.4.0 (384 kbytes)
I just solved my problem just like this:
1) Connect to the db with mysql workbench (select the "use old auth" and "send pass in cleartext"
2) Using the workbench, I ran the following several times (because it kept saying '0 rows affected'): (also change userID and password to your proper stuff)
SET SESSION old_passwords=0;
SET PASSWORD FOR userID=PASSWORD('password');
SET SESSION old_passwords=false;
SET PASSWORD FOR userID=PASSWORD('password');
3) Now go back to your app and it should run...
That is how I did it at least. I am using IX mysql and they do use old auth on their server so you must do something on your end...
I have not managed to solve the problem as the others who have responded, although I tried out everything that has been proposed.
In the end it turned out that the server on which stood my DB is not updated phpMyAdmin since version 3.5.5, and is currently being used everywhere version 4.1.14 and it is a problem.
The solution is to update your host phpMyAdmin or your own mySQL back to an earlier version in order to continue working on remote DB.
You may need this knowledge in order to solve some doubts that have arisen. :)
Today I found the same problem. I downloaded Workbench. There are some settings for workbench to connect database, as follows:
1.select tab SSL , select option 'no' in "Use SSL".
2. select tab advanced, select in Use the ole authentication Protocol.
after that Workbench working.
and follow tai1001' post.
That are all I found all steps that work.

Crystal report - Running thru .NET

I created a crystal report using test a DB. I run the report using .NET ReportDocument class. Everything works fine until I connect to the test DB.
When same report is pointed to UAT DB (all required DB objects are available in UAT too), I am getting error. To fix this, I have to change the server name to UAT DB manually in the RPT file.
How to fix this?
A solution is to create a system DSN (ODBC) for connecting to your target database. You can then switch the ODBC to whichever database you want (local,test,stage etc). Also, if you ensure an ODBC connection of the same name is available on all your servers, moving the report from dev->test->stage->production should be easy.
Using push reports should solve your issue. You can set up the report to accept a strongly-typed ADO.NET Dataset, and supply that dataset at runtime.
Isn't that how it's supposed to work? It has to know to what DB it's connecting?
Maybe I'm missing something but it sounds like you just needed to get the connection right.

Categories