Backup MariaDB database from Android client (Xamarin) - mysql

MySQLBackup.net works fine on Windows applications, but not in Xamarin (tested with exact same code).
Is there any workaround or alternatives that I can use ? I'm really lost...
I want to backup my database from a Linux (Debian9) MariaDB server, so I found MySqlBackup.NET, but nothing can make it work with Xamarin.
There's my code to backup (works in windows console app):
// Use MySqlBackup.Net to backup database
using (var conn = new MySqlConnection("myconnstring"))
{
conn.Open();
using (MySqlCommand cmd = new MySqlCommand())
{
conn.Open();
using (MySqlBackup mb = new MySqlBackup(cmd))
{
cmd.Connection = conn;
mb.ExportToFile(Constants.EXPORT_PATH + "/dolibarr_" + identifier + "dataBackup.sql");
conn.Close();
}
}
}
Getting exception: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.

Related

Connection to MySql database in ASP.NET Core

I am creating website in ASP.NET Core 2.0 and now I need to get data from my mysql database.
Database is located on hosting which use cpanel
In past I have created simple REST API which get some data from that database and it used this config:
server: db5.cpanelhosting.rs
Port: 3306
user: termodom_guest
pw: a1s2d3f4g5h6j7k8
Now problem is when I use code like this:
using (MySqlConnection con = new MySqlConnection("server=217.26.215.19;port=3306;database=termodom_TDMajstor;user=termodom_guest;password=a1s2d3f4g5h6j7k8"))
{
con.Open();
using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM KORISNIK", con))
{
MySqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
return true;
}
}
}
It drops me error
MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired.
The timeout period elapsed prior to completion of the operation or the
server is not responding. at
MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder
settings) at MySql.Data.MySqlClient.NativeDriver.Open().
I have also tried online testing connection but it also cannot connect. What to do?

aws mysql connection issue for azure site

I cant seem to find an answer to my issue.
I made a quick little website with .net and published it on azure.
when I test it I can query my aws mysql db just fine however after publishing I am getting.
System.InvalidOperationException: Connection must be valid and open. at
MySql.Data.MySqlClient.Interceptors.ExceptionInterceptor.Throw(Exception
exception) at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex) at
MySql.Data.MySqlClient.MySqlCommand.Throw(Exception ex) at
MySql.Data.MySqlClient.MySqlCommand.CheckState() at
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() at
TaskiiLink._Default.Page_Load(Object sender, EventArgs e) in
C:\............\Default.aspx.cs:line 39
line 39: MySqlDataReader reader = command.ExecuteReader();
my connection string is :
<add name="dbconn" connectionString="user id=NAME;Password=PASS;persistsecurityinfo=true;server=AWSENDPOINT;Port=3306;database=DB;" providerName="MySql.Data.MySqlClient"/>
page load code
if(Request["type"] == "1")
{
string sql = "checkDB";
conn.Open();
using (MySqlCommand command = new MySqlCommand(sql))
{
command.Connection = conn;
try
{
MySqlDataReader reader = command.ExecuteReader();
if (!reader.Read())
{
Response.Write("false");
} else
{
Response.Write("true");
}
You need to pass the connection object.
MySql.Data.MySqlClient.MySqlCommand myCommand = new MySql.Data.MySqlClient.MySqlCommand(insertQuery, connection);
Figured it out myself,
AWS security group was only allowing my local host ip as an inbound.
found my web apps outbound ip in the property settings in azure portal.
helpful links if anyone has the same issue.
AWS issue
https://forums.aws.amazon.com/thread.jspa?threadID=176030
azure info
https://social.msdn.microsoft.com/forums/azure/en-US/fd53afb7-14b8-41ca-bfcb-305bdeea413e/maintenance-notice-upcoming-changes-to-increase-capacity-for-outbound-network-calls
issue I had when adding the ip solution.
https://forums.aws.amazon.com/thread.jspa?threadID=158994

MySQL UWP "Could not load file or assembly"

I have a MySQL 5.7.20-log server running on Windows Server 2012.
I have created two simple applications:
1. C# Windows Forms application (.NET) using 6.10.4 Connector (NuGet package)
private void Form1_Load(object sender, EventArgs e)
{
TestMySqlConnection();
}
private void TestMySqlConnection()
{
string dbConnectionString =
" Data source = 192.168.0.12;" +
" Database = rcp;" +
" User Id = rcp;" +
" Password = *******;" +
" SslMode = None;";
using (MySqlConnection dbConnection = new MySqlConnection(dbConnectionString))
{
dbConnection.Open();
}
}
This application runs without problems.
2. Universal Windows Platform application (UWP /.NetCore) using 6.10.4 Connector (NuGet package)
private void Page_Loaded(object sender, RoutedEventArgs e)
{
TestMySqlConnection();
}
private void TestMySqlConnection()
{
string dbConnectionString =
" Data source = 192.168.0.12;" +
" Database = rcp;" +
" User Id = rcp;" +
" Password = *******;" +
" SslMode = None;";
using (MySqlConnection dbConnection = new MySqlConnection(dbConnectionString))
{
dbConnection.Open();
}
}
This application does not work and throws an Exception.
Exception:
Exception has been thrown by the target of an invocation.
InnerException:
FileNotFoundException: Could not load file or assembly 'System.Diagnostics.Process, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Any help would be appreciated.
Connecting to MySql database directly in UWP is a new feature which is introduced from .NET Standard 2.0.
For the previous Universal Windows Platform, it only supports .NET Standard 1.4.
So, that's the issue you're facing. I also can reproduce it on my side if I set my project's target version is 16299, but min version is the previous version (15063,14393 etc).
To solve this issue, you would need to make the project's target version and min version are 16299.

Getting "Access denied for user..." every 2nd hit

I'm trying to use dapper with mysql in .net core 1.0. I'm using this mysql connector: https://github.com/bgrainger/MySqlConnector
I know the connector is in alpha but I was wondering if anyone had a similar issue when using it together with dapper.
This is my simple model:
public List<GeneralModel> GetAllLists()
{
try
{
using (DbConnection connection = new MySqlConnection("Server=localhost;Database=lists;Uid=Unnamed;Pwd=lol;"))
{
return connection.Query<GeneralModel>("SELECT * FROM lists.general").ToList();
}
}
catch (Exception)
{
throw;
}
}
And this is the controller:
public IActionResult Index()
{
GeneralModel GenRepo = new GeneralModel();
return View(GenRepo.GetAllLists());
}
When I go to the index page for the first time, it works. If I refresh, I get an "Access denied for user...". I have no idea what could be causing the error. I don't think the problem is in my code.
Edit:
I guess the problem is in the connector, since this also returns the error after a refresh:
List<GeneralModel> lists = new List<GeneralModel>();
using (DbConnection connection = new MySqlConnection("Server=localhost;Database=lists;Uid=Unnamed;Pwd=lol;"))
{
using (DbCommand myCommand = connection.CreateCommand())
{
myCommand.CommandText = "SELECT * FROM lists.general";
connection.Open();
using (DbDataReader myReader = myCommand.ExecuteReader())
{
while (myReader.Read())
{
GeneralModel tmpGen = new GeneralModel();
tmpGen.name = myReader["name"].ToString();
tmpGen.description = myReader["description"].ToString();
tmpGen.language = myReader["language "].ToString();
lists.Add(tmpGen);
}
}
connection.Close();
}
}
return lists;
This bug was caused by MySqlConnector not correctly handling the fast path for a COM_CHANGE_USER packet.
MySQL Server (versions 5.6 and 5.7) doesn't appear to immediately accept the user's credentials, but always returns an Authentication Method Switch Request Packet. MariaDB (which you are using) does implement the fast path and immediately returns an OK packet.
The connector has now been updated to handle this response and should stop throwing the spurious "Access Denied" exceptions. The fix is in 0.1.0-alpha09.

Access2007 OleDbConnection over network share persists although share is deletedH

I've encountered a quite strange behavior of ADO.NET / Access 2007.
I run my C# 2008 program (target framework .NET 2.0) on PC1.
PC1 has a network share on PC2 (\PC2\Temp mapped as X:)
On PC2 in Temp there is the access database file xy.mdb
The program opens a OleDbConnection to X:\xy.mdb. Works fine.
Then while the program is still running I drop the share on PC2.
(Windows Explorer on PC1 tells me the share X: is lost)
I renamed the database file on PC2, so no new connection should be possible.
But the program can still query the database !
(via OleDbCommand.ExecuteReader() or ExecuteNonQuery())
Has anyone an explanation for me ?
Is the whole database latched ?
And can I prevent this so that I get an OleDbException when the share is dropped and I try to query the no longer available database ?
Thanks for any help,
Ralf
I tried to reproduce the issue with the following code and a sample access db...not matter how I tried (sahre or mapped drive) i always got the exception:
Unhandled Exception:
System.Data.OleDb.OleDbException: The
Microsoft Jet database engine cannot
find the input table or query
'somejunk'. Make sure it exists and
that its name is spelled correctly.
which is expected. You should re-examine you environment to be 100%.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;
namespace AccessOverShare
{
class Program
{
static void Main(string[] args)
{
int ct = 0;
using(OleDbConnection oleDbConnection = new OleDbConnection())
{
//oleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\127.0.0.1\\share\\test.mdb.";
oleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=w:\\test.mdb.";
oleDbConnection.Open();
using(OleDbCommand oleDbCommand = oleDbConnection.CreateCommand())
{
oleDbCommand.CommandType = CommandType.Text;
oleDbCommand.CommandText = "select junkid, junktext from somejunk";
using (OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader(CommandBehavior.Default))
{
ct = 0;
while(oleDbDataReader.Read())
{
ct++;
Console.WriteLine("{0:0000}", oleDbDataReader["junkid"]);
}
}
Console.WriteLine();
Console.WriteLine(ct);
}
Console.WriteLine();
Console.WriteLine();
Console.Write("kill the share then press enter to continue");
Console.ReadLine();
using (OleDbCommand oleDbCommand = oleDbConnection.CreateCommand())
{
oleDbCommand.CommandType = CommandType.Text;
oleDbCommand.CommandText = "select junkid, junktext from somejunk";
using (OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader(CommandBehavior.Default))
{
ct = 0;
while (oleDbDataReader.Read())
{
ct++;
Console.WriteLine("{0:0000}", oleDbDataReader["junkid"]);
}
}
Console.WriteLine();
Console.WriteLine(ct);
}
}
}
}
}