using method 'mysql_native_password' failed - c#

An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'#'localhost' (using password: NO)
I need to connect my database to the report viewer in visual studios however this error always appears and i dont know what changes i have to make...the password was already set to 'root' however this error still appears, I want to know what "(password: NO)" means since this only appeared when i accidentally flushed out the privaleges.

Password NO just means that you don't pass over a password.
Are you connecting like this:
string connsqlstring = "SERVER=" + server + ";PORT=" + port + ";user=" + user + ";password=" + password + ";database=" + databank;
sqlconn = new MySqlConnection(connsqlstring);
sqlconn.Open();
Or how are you doing it ?
Another thing is, i had problems before with Root and made a new User with which i now connect.
Maybe that helps.
Cheers,
Frozen :)

Related

C# Keyword not supportet - CertificateFile - MySqlConnection

I am trying to establish a SSL connection to a MySQL Server.
Now I get the following error, when trying to connect:
Unhandled Exception:
System.ArgumentException: Keyword not supported.
Parameter name: CertificateFile
here is my Connection String:
MySqlConnection connection = new MySqlConnection(
"database=database;user=sslclient;" +
"CertificateFile=C:\\Users\\LSP\\documents\\visual studio 2017\\Projects\\App1\\App1\\client.pfx;" +
"CertificatePassword=XXX;" +
"SSL Mode=Required");
Do you know what the fault is ? As mentioned in
https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-ssl.html
it is valid.
I also tried to manage this with a MySqlConnectionStringBuilder, but this also dont work:
enter image description here
I am using the newest Version of MySql.Data from the NuGet Manager.
Thank you for you help,
Louis

VSTO Excel Interop ListObject.AddEx (2010+) to ListObject.Add (2003) Conversion

As part of an Excel helper utility I'm developing I'm moving large commonly used Excel spreadsheets to MS SQL for performance as well as data validation via SSIS packages further down the line.
As part of this I wrote a basic Database Connection Class that mimics the Data --> From Other Sources --> From SQL Server button. I got this working at home using a copy of Office 2013, and I anticipated some conversion issues, primarily where the Excel Interop API has changed and upgrading to Office 2010 or above is not an option. My main problem seems to be conversion of the newer command AddEx:
MyListObjects.AddEx(ExcelAPI.XlListObjectSourceType.xlSrcQuery, MyConnection, Type.Missing, ExcelAPI.XlYesNoGuess.xlYes,StartRange);
To the 2003/2007 version Add as per MSDN (https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.listobjects.add(v=office.11).aspx)
//2007 command//
ExcelAPI.ListObject CurrentTable = MyListObjects.Add(ExcelAPI.XlListObjectSourceType.xlSrcExternal, MyConnection,Type.Missing,ExcelAPI.XlYesNoGuess.xlYes,StartRange);
The exception I'm getting is:
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code Additional information: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
My initial thought was changes in the ExcelAPI.XlYesNoGuess enumeration, so I tried manually values, but I then encountered compiler errors. I've tried removing the parameters one at a time using Type.Missing to trace the culprit however this seems to have caused more errors than it solved despite MSDN stating these are all optional.
The connection string made up like this:
String FullString = "OLEDB;Provider=SQLOLEDB.1;Data Source= " + PCNameOrIP + #"\" + InstanceName + #";Initial Catalog=" + DatabaseName + #";User ID=" + DatabaseUserName + #";Password=" + DatabasePassword;
Method test call parameters:
Globals.ThisAddIn.DM.EstablishConnection("BREWL14H58107", "SQLEXPRESS", "TestDB", "sa", "Password0", "SELECT * FROM TestDB.dbo.Test", "Demo File", "Testing");
Having done looked into this some more. It seems the code I have works fine from home, the amended Add. However from work I am still getting:
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code. Additional information: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

Unable to read local SQL Server file when running as exe. Works in IDE

This is the first time that I am trying to use a SQL Server File type database. It works when I run in the IDE but when I double click on the exe or right mouse click "Run Elevated," I get an error when trying to connect.
The message box displays the same connection string when running in both modes.
What might be the issue? Some sort of permissions issue?
MessageBox.Show(ApplicationParameter.LocalDatabaseConnectionString);
databaseConnection = new SqlConnection(ApplicationParameter.LocalDatabaseConnectionString);
databaseConnection.Open();
I get the following SqlException:
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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed to start.
Here is the connectionstring from the app.config file:
<connectionStrings>
<add name="LocalDatabase" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=C:\MYCODE\MyCompany.DISKMONITOR\MyCompany.DISKMONITOR\DATA\DATABASE.MDF;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"/>
</connectionStrings>
And my class for reading the app config:
class ApplicationParameter
{
public static string LocalDatabaseConnectionString
{
get
{
return ConfigurationManager.ConnectionStrings["LocalDatabase"].ConnectionString;
}
}
}
Update:
I ran as Administrator and got the same result.
Connections.Classified contains information specific to the location of the db, what instance to use and username/password information. Will not be posted...
Here is my SQLConnections.cs class that I use in all of my apps (well mine is oracle I've just updated it to work with SQL):
private String connectionString = "Server=" + SERVER + "\\" + INSTANCE + ";Database=" + DATABASE + ";User Id="+ USER + ";Password=" + PASSWORD + ";"
protected SQLConnection getConnection()
{
return new SQLConnection(connectionString);
}
In use in a repo class that extends the Connections.SQLConnections:
SQLConnection connection = getConnection();
A lot less clutter and easier for someone else, reading your code, to understand.

C# Connect to MS SQL Server using Active Directory Service Account

I have a stand alone application that works great with a Local user account in MS SQL. When I try to use an active directory service account instead I appear to be running into problems.
It appears Microsoft want's the exe to run as the domain user service account which is not an option for me. Looking at alternatives, one person mentioned having main exe launching a second exe that does the work or having a local windows service.. neither of these are an option either. It feels like this is getting more complex then it needs to be.
Here is an example of the piece of code I am working with:
private void MakeConnection(){
string ServerNM = #"MyServer";
string Database = #"Test01";
string Username = #"testdomain\testuser";
string Password = #"testpass";
string connection_string = "Server=" + ServerNM
+ "; Database=" + Database
+ "; User ID=" + Username
+ "; Password=" + Password
+ "; Max Pool Size= 1000;";
try {
SqlConnection oSqlConnectionTest = new SqlConnection(connection_string);
oSqlConnectionTest.Open();
}catch(Exception oException){
MessageBox.Show("Error: " + oException.ToString());
}
}
Is this a real limitation or am I missing something?
SQL Server does not accept domain accounts in the connection string for security reasons.

Retrieving Database Compatibility Level - Different Result for Same Server/DB, Different Users

I have the following code to determine a SQL Server database's compatibility level:
Microsoft.SqlServer.Management.Smo.Server server = new Server(myServerName);
if (!server.Databases.Contains(database))
{ throw new ArgumentException("Specified database ('" + myDBName+ "') not found on '" + myServerName + "'"); }
string connstr = string.Format("Data Source={0};" +
"Persist Security Info=False;" +
"User ID={1};" +
"Password={2};Enlist=False;", myServerName, username, password);
server.ConnectionContext.ConnectionString = connstr;
Microsoft.SqlServer.Management.Smo.Database db = server.Databases[myDBName];
DataSet ds = db.ExecuteWithResults(#"select compatibility_level
from sys.databases where name=db_name()");
I have two users, one of which is able to run this code and get the proper value back. Another user runs this code connecting to the same Server/Database with the exact same credentials and the DataSet returned contains no rows.
What could possibly be the difference between the two users that would cause one to get no result back for the same query? Is there a better way to get Database compatibility?
By the way, this code runs/works on SQL Server 2005 through 2012.
Edit: I should have pointed out that myServerName, myDBName, username, and password are always the same--the only difference is the two different Windows users running the code.
I suspect that the user who returns results has the VIEW_ANY_DEFINITON permission granted to his login. Grant this permission to the other user and he should get the results back.

Categories

Resources