Answer the question
In order to leave comments, you need to log in
Is it even possible to organize a local MySQL for C#, accessible to the connector from the program?
There is a database for MySQL in ".sql" format. Is it possible to install locally MySQL + phpmyadmin on a machine, and even so that it is available for the C# connector on the same machine (which is without the Internet, by the way)? Ready-made sets of local servers (Denwer, OpenServer) are installed and working, but the base for C # is not visible. Only for php. There is reason to suspect that the connector a priori "cannot" without the Internet.
When connecting, I tried to specify as IP: localhost, 127.0.0.1
Answer the question
In order to leave comments, you need to log in
Of course available. Internet is not required for local connections.
The connection string is something like this:
where:
If a non-standard port is used, then it can be specified separately: Port=123 .
Denwer and others are not needed here at all. It is enough to download the official MySql distribution kit and install it.
With MySQL Workbench , you can manage databases through a graphical interface.
The code for getting data from MySql in C# might look something like this:
var connectionString = "Server=localhost;Database=example;UID=username;Password=password";
using (var connection = new MySqlConnection(connectionString))
{
// открываем соединение
connection.Open();
// создаем команду
var cmd = new MySqlCommand();
cmd.Connection = connection;
cmd.CommandText = "SELECT * FROM table1";
// создаем адаптер
var adapter = new MySqlDataAdapter(cmd);
// создаем таблицу
var table = new DataTable();
// получаем данные в таблицу
adapter.Fill(table);
// выводим
foreach (DataRow row in table.Rows)
{
Console.WriteLine(row[0]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question