I am developing c# windows application.
In that I want to connect to mysql database which resides in another system.
Please help me to solve this?
Assuming that you know how to connect to and query a database, you'll need the following:
The ADO.NET provider for MySQL
The hostname or IP address of the server
A user ID and password to connect with
Add a reference to the MySQL provider. From there, it works just like connecting to a SQL Server box, except the class names are a bit different and some minor SQL dialect is also different.
Of course, if you don't already know how to connect to a database, you'll need to start a bit slower. I'd recommend you Google yourself a basic data-access tutorial.
Good luck!
Related
Apparently, using AttachDbFilename and user instance in your connection string is a bad way to connect to a DB. I'm using SQL server express on my local machine and it all seems to work fine. But what's the proper way to connect to SQL server then?
Thanks for your explanation.
Using User Instance means that SQL Server is creating a special copy of that database file for use by your program. If you have two different programs using that same connection string, they get two entirely different copies of the database. This leads to a lot of confusion, as people will test updating data with their program, then connect to a different copy of their database in Management Studio, and complain that their update isn't working. This sends them through a flawed series of wild goose chase steps trying to troubleshoot the wrong problem.
This article goes into more depth about how to use this feature, but heed the very first note: the User Instance feature has been deprecated. In SQL Server 2012, the preferred alternatives are (in this order, IMHO):
Create or attach your database to a real instance of SQL Server. Your connection string will then just need to specify the instance name, the database name, and credentials. There will be no mixup as Management Studio, Visual Studio and your program(s) will all be connecting to a single copy of the database.
Use a container for local development. Here's a great starter video by Anna Hoffman and Anthony Nocentino, and I have some other resources here, here, and here. If you're on an M1 Mac, you won't be able to use a full-blown SQL Server instance, but you can use Azure SQL Edge if you can get by with most SQL Server functionality (the omissions are enumerated here).
Use SqlLocalDb for local development. I believe I pointed you to this article yesterday: "Getting Started with SQL Server 2012 Express LocalDB."
Use SQL Server Compact. I like this option the least because the functionality and syntax is not the same - so it's not necessarily going to provide you with all the functionality you're ultimately going to want to deploy. Compact Edition is also deprecated, so there's that.
Of course if you are using a version < SQL Server 2012, SqlLocalDb is not an option - so you should be creating a real database and using that consistently. I only mention the Compact option for completeness - I think that can be almost as bad an idea as using AttachDbFileName.
EDIT: I've blogged about this here:
Bad Habits : Using AttachDBFileName
In case someone had the problem.
When attaching the database with a connection string containing AttachDBFile
with SQLEXPRESS, I noticed this connection was exclusive to the ASP.NET application that was using the database. The connection did block the access to all other processes on the file level when made with System.Data.SqlClient as provider.
In order to assure the connection to be shareable with other processes
instead use DataBase to specify the database name in your connection string
Example or connection string :
Data Source=.\SQLEXPRESS;DataBase=PlaCliGen;User ID=XXX;password=ZZZ; Connect Timeout=30
,where PlaCliGen is the name (or logical name) by which SQLEXPRESS server knows the database.
By connecting to the data base with AttachDBFile giving the path to the .mdf file
(namely : replacing DataBase = PlacliGen by AttachDBFile = c:\vs\placligen\app_data\placligen.mdf) the File was connected exclusively and no other process could connect to the database.
I have developed a winform application in C#.net and using SQL Server 2008.
My application inserts and updates values into database.
Is it possible to install the application on a another system which doesn't have sql server on it?
Imagine using sql azure. Cloud based sql server. The database is never on the same physically computer. It's all down to the connection string.
With an on premise database you need to make sure the database allows external connections, maybe opening up firewall etc. then make sure the connection string is set correctly on the application to talk to external database.
You can even configure to change the connection string as required pointing at different databases depending on the individual requirements.
Scott
Yes, you can. You can access the DB remotely by referring remote DB server in connection string.
It is possible, if you are looking to run the application on machine that is running on the same Domain as the SQL Server and has privileges to the SQL Server.
I'm in the folowing scenario:
I have a local application in WPF C# and I want a centralized database on a server (Webhotel). Security is not a critical matter at this point and there will only be one or two instances of the client application. It's not my own server so I don't have control over the server settings. I do, however, have access to a SSH account on the webhotell. I Use VS2012.
My question is:
How do I connect to the MySql database and use it's data using "best practice" or any alternative. Upsides/downsides.
Also, if you do suggest using SSH, I whould realy appriciate code examples or links to tutorials.
I regularly run the same SQL command against multiple different oracle databases we have. I am trying to create a simple C# program that will allow me to run the command and display the data in a DataGrid. I am not the DBA of the database and currently have access to to the DB's using SQL+. Is there a way I can connect to the database, run a statement and disconnect so that it runs a the database end in exactly the same way as if I had used SQL plus?
I have seen different methods of connecting to oracle from C# but my question is mainly aimed to find out which one would work in my current setup, where SQL+ works.
It won't matter in which way you connect to the database. The privileges are connected to your username the Oracle database. SQL+ is just a tool you use to connect to the database.
So if you're able to connect to the database in code with your username you can issue the query the same way you would in SQL+.
I'm a newbie.. So, please forgive me if it's a simple question :)
I'm developing a system to get some specific data and store it to a database using C#. I have almost finished the system.
I'm using a MySql database running locally on my machine. I need this database to be accessed remotely so that my employer can view the data. He told me to create a phpMyAdmin interface for the database, but I don't have experience with this.
I need the solution to be free, please.
Thanks in advance.
phpMyAdmin is free. You just have to download and install it on the machine with MySql. You will also need a WAMP stack (PHP web server hosting, such as the free WampServer package) to execute the phpMyAdmin website, and open the ports in your router to allow viewing the webpage remotely. Also there might be configuration settings in phpMyAdmin to allow remote access, but all these things have been done many times before and you should be able to find lots of help by googling.