I am creating an wpf application which gives user an option to backup an mysql db.I want to get this done in C# coding.
I know that it can be easily done using mysqldump, but i am stuck in an scenario where there is no mysql server installed on local machine and the user wants to back up the db located on remote machine.
So here's where i need help or any suggestion how this can be achieved as i will not get the mysqldump on local machine as mysql server is not insstalled.
I also know that back of mysql db is not possible without using mysqldum utility provided by MySql.[did an google over here and didnt found any helpfull post].
What I tried :
I was trying to embed the mysql dump with an application but somehow i was not able to.
What I want to achieve :
I want to create an back up of mysql db even though the user havn't installed the mysql server on his local machine.
EDIT :
Is there an MySqlCommand which backups the db like the ms sql server one
[ BACKUP DATABASE inventory TO DISK]
This is just for the data, not the table structures, triggers, etc: an exporter to XML, see here
Get a list of the tables:
SHOW TABLES;
Get an SQL statement that will create the table:
SHOW CREATE TABLE table_name
Use SELECT * FROM table_name to get the rows and format them like
INSERT INTO (some_field, another_field, ...) VALUES ('one','two',...)
You can try SQLyog's Scheduled backup/Backup as SQL dump to backup remote MySQL database from local machine. If you have installed SQLyog on local machine you can connect to the remote server and backup using SQLyog.
Related
I have my application written in C#, it uses a SQL Server database. I have a connection to a database in my C# code, some queries to write/read from database.
Now consider following: if I want to run this app from another PC, this PC has no SQL Server, will this app work? (I assume not) If not then how can this another PC still work with database? Is there a way to programmatically create database on another PC using C# so it has a name I need, columns I need. I created my database using SQL Server Management Studio.
I guess your application works with a local server.
First of all you should check in your application at startup if there is any local mssql server running. If not, you should handle it by installing one programmatically.
Read this answer how to do this if you don't know it.
After that you have to create the database, it's tables, maybe adding user priviliges. Write a SQL script that gets started by a class that starts it.
Read this to see how to start a SQL script in C#
You can do this by setting up SQL server on another machine (server).
Set that servers authentication to SQL Server authentication (requires username and password for that SQL server Management Studio)
Change the connection string in web/App.config from your C# app to use that servers Ip address and Credentails for SQL server
I would like to create a new VisualStudio project with a simple SQL server db, but i want it to be portable, because several people will need to have access to the DB.
So it should be also accessible from a user with password.
The point is that when i create a Local SQL server DB i can't create a new user because it sais You can only create a user with password in a contained DB.
Is there a way to create a Local DB with password or a way to let several user access to the same DB?
Thx
Is there a way to create a Local DB with password
Yes. I'd recommend using Sql Server CE or SqlLite for a database like this. If you're only using Sql Server as a data store on the local machine, Sql Server, even Express Edition, which is still the full Sql Server engine, is usually way overkill for this. The full Sql Server engine really only makes sense when the database engine is the sole, exclusive reason that the machine where it runs exists.
Is there... a way to let several user access to the same DB?
Yes. Install Sql Server on a dedicated database machine, instead of using a Local DB, and set the appropriate connection string and permissions.
Here's the trick: you can't do both, at least not without going through all the same trouble you'd go through setting up a real Sql Server to run on the machine where this will be installed.
I have a very unusual problem. I made a project in C#.net in vs 2008 and SQL server 2005.
I have two DB to use.
Now, the problem is whenrunning the project on my PC it works fine, but when i install on users PC, through setup, im getting a exception handler error , when im trying to save any data in either of the DBs. However i tried to insert data through INSERT INTO coomand in sql it works fine. And i have no problem in retrieving data.
So any one can help please do.
Thanks in advance
How are you specifying your connection to the database(s)? If you're doing windows authentication, most likely your user's accounts don't have permissions on the database. It could also be that they can't see the database from where they are on the network.
I'd start by pinging the DB server from the user's machine to make sure they can even access the server.
I have a simple code that is using C# and Sqlserver 2008.
For my C# code I get the .EXE file to customer and forced to install the .NET framework on her computer to run just the C# code.
But about the Sqlserver; I have installed the complete Sqlserver on my PC then attached my database on management part of that and am using the Sqlserver
now that I want to get my program to customer I install the .NET framework; but how can I run Sqlserver on her computer and attach the database each time?
Lets me to explain more:
The program will use on a local network and is multi_user.
I installed and am using the Sqlserver on my PC. I created my database and it's tables by help of sqlserver management tool.
for connecting to the datatbase I wrote a code that connect via the users IP address and I tested it on my PC with 2 Virtual machine. It is working truely.
My problem is here:
When I get the program to customer, what I have to do exactly?
What about the database I have to do?
I have to install the whole Sqlserver on customer PC and set that PC as a server or I have a better way to do this?
Thanks.
If you want to use sql server as an embedded database for local storage, use sql server CE.
If you want your users to have access to a shared database you'll have to instal sql server (sql server express may do) on some machine in their network, configure the access rights, and adjust their connection strings accordingly. Or use SQL Azure.
I have to install the whole Sqlserver on customer PC and set that PC
as a server or I have a better way to do this?
yes you have todo all this work
1)install sql server and the management
2)install your database
3)remote your database to be used
I'm a dektop developer and don't know much about how webhosting work... So please help me here.
currently my app works with MSSQL database which is installed locally on the same machine.
Now I need to go wider and let multiple apps work with the same database over the Internet.
I have a webhosting with CPanel in it and MySQL database.
Please tell me how I can access tables in that MySQL database from my another computers?
Select and update records in that table. Do I have to implement some functionality using PHP to make such requests?
Please advise..
Exporting raw MS-SQL dumps will probably not work if you try to import into mySQL because there are some differences in syntax. There are commercial programs available that will help you migrate data, otherwise it might be better to code a PHP program to export from MSSQL to mySQL.
But your question sounds more like you're asking how to access databases remotely.
.
PHP can do this natively. When you create your link to the database you specify the host. For example: $databaseConnection = new mysqli('username','password','host_ip_address');
If you're coming from MSSQL you may hit some snares.
To allow remote connections on MS-SQL you use the "surface area" configuration tool. You'll probably find that your mySQL database server is already configured to allow remote connections, if not you'll have to take that up with your host (sounds like you don't have your own box).
The next trick is to remember that usernames in mySQL look like this: 'user'#'host'.
cPanel hosting usually has PHPmyAdmin installed. Open it up and look at the user table in the mysql database (the actual database named mysql running on the MySQL server).
You'll see a host column. So if your 'root' user is only set to 'localhost' you won't be able to login as that user from another machine. The wildcard symbol is %. You can read this up here - http://dev.mysql.com/doc/refman/5.5/en/adding-users.html
Of course the same rules apply to mySQL when it comes to users. Don't use your root account to access sub-databases, rather assign new users which only have the required permissions. Also consider using non-predictable usernames. That doesn't really answer your question (sorry) but it's worth mentioning while you're looking at the user table.
So to finally answer your question:
1) login to cPanel and create your database 'foo'
2) Run SQL command:
GRANT ALL PRIVILEGES ON foo.* TO 'secretuser'#'%' IDENTIFIED BY 'longpassword'
Then PHP code would look something like this:
$host = 'ipaddress or hostname';
$mysqli = new mysqli('secretuser','longpassword',$host,'foo');
// look in php.net for error handling
$query = "SELECT * FROM tablename LIMIT 0,10";
$result = $mysqli->query($query);
The reason I put a limit there is because you're probably used to "SELECT TOP 10"
You would have to export the data on your computer into a raw SQL file, and then using a the PHPMyAdmin control panel you could import it. Assuming you are also using PHPMyAdmin on your own machine there is an 'Export' tab along the top. If you click on that you will have the option to export all your tables to a .sql file.
From there you then need to access PHPMyAdmin via CPanel. Once in you can then hit the 'Import' tab and upload your file to get all the data into the database. To interact with the database online you would need to use the inbuilt functions in PHP - the MySQL Reference on PHP.net is very useful. you would then be able to access the database from any computer using the PHPMyAdmin control panel.