"The used command is not allowed with this MariaDB version" - c#

I have Added SslMode='none' part to the data source in the connection string since there was a MySQL exception called,
“The host localhost does not support SSL connections.”
I referred this solution in StackOverflow.
Solution
After that, the error was gone. But when I tried to Debug using step into in the 2nd iteration of the program there was an error,
The error triggers in bl.Load(); in the below code
library.WriteErrorLog("Update The Table");
MySqlCommand comm = conn.CreateCommand();
comm.CommandText = "TRUNCATE TABLE jobs";
comm.ExecuteNonQuery();
conn.Close();
library.WriteErrorLog("truncate Table");
bl.Load();
"The used command is not allowed with this MariaDB version"
The connection string is as follows:
string connStr = "data source=localhost; UID='13user';database='13shop';port=3306;password='123';SslMode='none'";
Any clue about this error?

Related

How to establish SQL Connection in Visual Studio using local mdf file

I'm new to coding. I'm attempting to access a SQL Server file through WPF / C# and I am having trouble getting in the correct string, I believe. I do not yet fully understand SQL logins, but here is the code I have now, which I believe as close to correct as I can get on my own:
string CS = #"Data Source=(LocalDB)\v11.0; Integrated Security=true; AttachDbFileName=C:\Users\Madison\source\repos\TheRealStudyBot\TheRealStudyBot\TestingData.mdf";
SqlConnection con = new SqlConnection(CS);
SqlCommand cmd = new SqlCommand("CREATE TABLE table1 (PK int, Name nvarchar(255), PRIMARY KEY *PK),);", con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
con.Close();
This code is under public MainWindow(), after InitializeComponent(). The file path should be correct. The database is empty. I get this exception:
Win32Exception: Unknown error (0x89c50118)
Ran it once more and I think I may have accidentally altered my debug settings because now it also provides a window stating
The solution does not contain the specified document
(along with plenty of other jargony-code-exception-results-text). I don't see where I'm going wrong. Please help!
If you are on Visual Studio 2019,
Double Click on your LocalDB which opens Server Explorer
Clicking on your database, On the properties tab shows the connection string.
Copy that & Paste on CS!
And the Normal Connection String Format For LocalDB is,
Data Source=Your_DataSource;Initial Catalog=YourDatabaseName;Integrated Security=True;Pooling=False

System.Collections.Generic.KeyNotFoundException upon attempting to log in to .NETCore application with MySqlClient

I'm building an contact manager application using .Net 5.0 in Visual Studio 2019 Community Edition. I am using MySql Connector (MySql.Data.dll) to connect to MySql database. The connection works, though only after adding the older version (6.1.2) - it is possible to insert data to the database. However, upon searching through the database (logging in or verifying whether the username already exists - here the error is more specific, listed below) I am receiving such an error:
System.Collections.Generic.KeyNotFoundException: „The given key
'utf8mb4' was not present in the dictionary.”
Here is my connection string:
MySqlConnection con = new MySqlConnection("datasource=localhost; port=3307; username=root; " +
"password=; database=csharp_contact_manager_db; CharSet=utf8;");
Here's my code for logging in functionality:
Database db = new Database();
MySqlDataAdapter adapter = new MySqlDataAdapter();
DataTable table = new DataTable();
MySqlCommand command = new MySqlCommand("SELECT * FROM `user` WHERE `username` = #un AND `password` = #pass", db.getConnection);
command.Parameters.Add("#un", MySqlDbType.VarChar).Value = textBoxUsername.Text;
command.Parameters.Add("#pass", MySqlDbType.VarChar).Value = textBoxPassword.Text;
adapter.SelectCommand = command;
adapter.Fill(table);
The aforementioned error always occurs for adapter.Fill(table) line.
Here's the query I'm using for verifying whether the username already exists in the database:
string query = "SELECT * FROM 'user' WHERE 'username'=#un";
In case of the above verification, this is an error I'm receiving:
MySql.Data.MySqlClient.MySqlException: „You have an error in your SQL
syntax; check the manual that corresponds to your MariaDB server
version for the right syntax to use near ''user' WHERE
'username'='user'' at line 1”
I downgraded the MySql.Data.dll version, since this is what I've receiving so far when attempting to connect to the database with the version of 8.0.17:
System.TypeInitializationException: „The type initializer for
'MySql.Data.MySqlClient.MySqlConnectAttrs' threw an exception.”
FileNotFoundException: Could not load file or assembly
'System.Management, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file
specified.
I've already seen similar posts regarding this, none of the suggested solutions helped in my case though.
Cheers,
Filip

Unable to connect to database using Oracle.ManagedDataAccess and Windows Native Authentication

I am having trouble connecting to an Oracle database using Oracle.ManagedDataAccess and Windows Native Authentication.
I am developing on a workstation from which I am able to connect to the same database using NTS via the PL/SQL Developer, and via C# code using non-managed Oracle.DataAccess. This leads me to I believe that there is nothing fundamentally wrong with either the database, workstation or the account. Now I am trying to evaluate if it's possible to switch to Oracle.ManagedDataAccess in our solution.
I've tried the following so far:
Created a new blank project OracleManagedAccessTest
Under references added the NuGet package Oracle.ManagedAccessTest v19.3.1 (the latest at the time of writing)
Update the <dataSource> tag in the App.config to match the entry in the tnsnames.ora (to make the C# project self-contained and not relying on external component)
Added <setting name="sqlnet.authentication_services" value="NTS"/> tag under <oracle.manageddataaccess.client><version number="*"><settings> in the App.config
I am using the following minimal code to test the connection:
try
{
using (OracleConnection conn = new OracleConnection("Data Source=EDBDEVD;User Id=/;"))
{
conn.Open();
}
}
catch (OracleException ex)
{
Console.WriteLine("Exception Message: " + ex.Message);
}
The attempt to connect fails with the following error: "ORA-01017: invalid username/password; logon denied"
This looks almost like too simple of a problem, yet I can't seem to resolve it, or find a workable solution online. Any help would be greatly appreciated.
Try this one:
string oradb = "Data Source=ORCL;User Id=hr;Password=hr;";
OracleConnection conn = new OracleConnection(oradb); // C#
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select department_name from departments where department_id = 10"; cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
label1.Text = dr.GetString(0);
see also: https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/GettingStartedNETVersion/GettingStartedNETVersion.htm

SqlConnection, Getting error and cannot connect to the database (occurred in System.Data.dll)

I have just stared to learn C# 2 Weeks ago so I dont know much but right now I just want to make my first program I don't really care about the security flaw within ATM as I will fix these with time when I know a better solution.
So I got this error:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll
Additional information: A severe internal connection error has occurred.
And I have been sitting with this error for 2 days now modifying my code and searching the internet for solutions with no luck. So I turn here as I see there are some experts here.
Code with error:
using (SqlConnection con = new SqlConnection("server=SERVERIP,3306;Integrated Security=True;database=data;uid=USER;password=PASS"))
{
con.Open(); //ERROR HERE
using (SqlCommand cmd = new SqlCommand("insert into info(Datum,Timmar,Rast) Values(#Datum,#Timmar,#Rast)", con))
{
cmd.Parameters.AddWithValue("#Datum", textBox1.Text);
cmd.Parameters.AddWithValue("#Timmar", textBox2.Text);
cmd.Parameters.AddWithValue("#Rast", textBox3.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Sparat!");
}
}
So basically what I am trying to do with this program is so that the data that the user types into the textboxes gets saved in the database.
When I type word with full capital letters I mean that it's something else there eg. Ip and password etc.
You are using the wrong connection class. You are trying to talk to a MySQL database as if it were a SQL Server database.
You need to use MySqlConnection, not SqlConnection. MySqlConnection is in MySQL Connector/NET, which can also be installed via NuGet.
Your code should look like the following instead.
using (MySqlConnection con = new MySqlConnection("server=SERVERIP;port=3306;database=data;uid=USER;password=PASS"))
{
con.Open(); // Hopefully no error here any more
using (MySqlCommand cmd = new MySqlCommand("insert into info(Datum,Timmar,Rast) Values(#Datum,#Timmar,#Rast)", con))
{
cmd.Parameters.AddWithValue("#Datum", textBox1.Text);
cmd.Parameters.AddWithValue("#Timmar", textBox2.Text);
cmd.Parameters.AddWithValue("#Rast", textBox3.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Sparat!");
}
}
You have Integrated Security=true AND uid=USER;password=PASS
If you are providing username and password you shouldn't have Integrated Security=true

Can't create a sql connection due to the fact that it won't rcognize the data source keyword

Hello I'm trying to run a simple sql command on a DB from MS VS C# 2010 and I have encountered a error I have never seen before the relevant code is:
SqlConnection comCon = new SqlConnection(#"Data Source=C:\\Users\\George\\Desktop\\programming\\C#workspace\\Projects\\Examen\\Examen\\Companie.mdf;Initial Catalog=Proiect;Integrated Security=True"); 
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "UPDATE Proiect SET Buget = Buget + 500 WHERE (Buget > 0)";
cmd.Connection = comCon;                                                      
comCon.Open();
Console.WriteLine(cmd.ExecuteNonQuery().ToString());
comCon.Close();
And the error is Keyword not supported: 'data source'
The main problem is that I'm not used to creating these sqlconnections by hand so please tell me if I'm missing something.
You are using the wrong structure. To attach a database file, you need to use the following structure:
SqlConnection sqlConnection =
"Server=DatabaseServerName;AttachDbFilename=d:\Database\Database.mdf;
Database=DatabaseName; Trusted_Connection=Yes";
You need to have the right permissions on both the target file and database server to attach the databse and establish the connection.
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
If it's not an ASP.NET application don't use the DataDirectory syntax and just use the full c:... path.

Categories

Resources