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.
Related
I'm currently working on a school project which I almost finished. I tested it and it was working fine on my local machine. Then I uploaded it to a webserver to test it and I got an error.
Apparantly you have to configure an external MySQL server and database to get the ASP.net membership system working. (I know it's stupid but I honestly didn't know).
So now I've managed to get a free database (since it's for school purposes it doesn't matter) and I want to save the required information for the membership service in this external database.So now I have to do these three things:
1.Getting to know which columns from the local database I have to insert in the external database (e..g. username: VARCHAR(20) etc.) I need to get this info from my local database...
2 replacing the connectionstring in my web.config file to get it working with my external database.
I searched the web a lot but couldn't find the right thing to do: GETTING TO KNOW THE COLUMNSI read online it was useful to use Microsoft SQL server management. I downloaded it so I could connect to my local (automatically generated) database. I couldn't figure out how to log in. Using my machine name or just a '.' both doesn't work....edit: this is what I mean (picture) what should I do?
REPLACING THE CONNECTIONSTRING
To be honest, I don't understand the connectionstring at all...
If anyone know what to do in these two problems I would really appreciate the help!
Thanks in advance,
Elias
You seemed to ask several questions (above) so I will try to answer enough of them to get you pointed in the right direction.
First, MySQL is not the same as SQL Server. They are different/competing products. From your comments, it sounds like you need to attach a .MDF file which is a "Microsoft Database File". Instead of MySQL, you need to install SQL Express (free). SQL Management Studio will allow you to attach your .MDF file and set up permissions, etc.
Since this is for school, you can use your DB mgr to create a test account with a simple PW. It could be something simple like User: Demo, Pw: D3mooo{ (or whatever you can remember). By default Sql Server only allows you to grant permissions to accounts from your OS. To change that, you can use SSMS, right-click the server, choose Properties, security and change the "Server authentication" to "SQL Server and Windows Authentication mode". Otherwise, you could just grant permission to your IIS server's identity, which is usually some name like [machinename\IUSR] (with square-brackets).
Once that is set, you need to create a "connection string". The easiest way is to create a text file on your desktop and rename it from new text Document.txt to dsn.udl. The file extension is the trick, it must be .udl instead of .txt. If you get it right, the icon will change and you can double-click it and go through the wizard to make/test a connection string. When you are done, you can open the udl file with notepad, and it will contain a working connection string. Copy the connection string into your web.config and things should start working for your membership DB.
I've been searching about this on Google and I did find some useful stuff but I'm not totally sure if that's what I need so I'll ask here.
I'm trying to make a Windows Store application and I want to connect to a simple MySQL database that's on the server. What's the easiest or best way to do that? Whenever I need local databases I use Entity Framework. Is it possible to use it here and if so, are there any tutorials that cover everything that I need to install as well as some code examples?
My advice for you : read more about Database Engine :) cause once you connect you DB Engine to a Database : either it is local or on remote machine (Server) its the same thing when you look at it from your application.
1- First watch this read more about this : SQL Server Management Studio
2- watch this (how you connect to a remote database) enter link description here
3- Very important is to allow connection from Remote Machine enter link description here
4- Once you are able to connect to the remote database from your SQL Server, everythg is the same on EF.
Normally when we connect to a database, we will select the database driver
type, server name, uid, password and database name. (like ms
sql server ). Is it possible my c# windows form app
auto detect available database connections?
Maybe the ms sql server database is store on the same PC where I
am running the app.
It is like the app can know there is a ms sql server
database and try to connect to the database.
I will aprreciate if you can please provide some example code
Thanks
The SqlDataSourceEnumerator API may be what you are looking for, however I rarely see it used - in part because not everyone wants their servers discoverable, so they turn this feature off. Additionally, even if you can find the servers, it certainly won't tell you the credentials - you need to know those yourself (or use trusted auth).
But in almost all cases (unless you're writing a database utility like SSMS): your user should already know which source they need to connect to (even if that is just a magic opaque string that the admins give them).
For more info, see MSDN which has a full example.
I have a nice program idea, it will be a very simple application that will save your username and password on a sql server database file, i know how to do it, but the problem is i don't want the client to install sql server in order to add or remove a record in database, besides i want my database file embedded into the application so the user have a single .exe file, i heard about a library called sqllite or something, it`s function is not to let the user install sqlserver to make the application work.
You can use SQLCE and search for SQLCE private deployment, basically it is a light weight of MS SQL on client side. With privatedeployment you just need to copy related DLLs to your project folder without installation.
You are looking for SQL Server Compact edition.
You need to use a file based SQL database.
There are several - most popular are:
SQLite
SQL Server CE
See this SO question - Free portable database.
As you mention, Sqlite is an option. It's a compact and file based database. No need for installing anything. The full database resides in a file. You'll need to reference the Sqlite database engine for connecting to it, however.
I probably wouldn't use SQL at all if you are only going to create one table with a few (< 100) rows. Its way to much overhead for that small amount of information.
I would save the username and password in a file, then use the Enterprise Libraries Cryptography Application Block to secure the file.
You also most likely don't want the storage engine embedded into the exe, then your passwords are tied to that specific application on that specific computer. You will have to implement an import/export program anyway to move your info to another machine.
Check out http://keepass.info/
Yes , you can implement it by
SQLite ,
SQL Server CE ,
Or Xml
And also , in my last project , the application call the webservice when need to access DataBase.
So , there are lots of ways to avoid install SQL Server on client PC .
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.