Please forgive me if the title is not correct. I am still trying to understand how this works.
I have installed MySQL workbench and the MySQL server on my laptop. I have successfully created a database that store driver details, as per the picture.
I can access this info only one my laptop. However, I would also like to access this info from other PC's. I was thinking of having the main database in a secured room and then connecting about 3 additional PCs to the main database.
I have also written a simple c# script on Visual Studio that runs on my main laptop where the database is stored. This script just allows a user to enter his username and password and then displays the contains of the database (the table in the database) on a datagrid view. I have included the SQL injection code to prevent unwanted characters. This application also allows the user to insert, update, and delete info from the database provided the user that logs in has these privileges granted.
Now I would also like to run this application on the other 3 PC's, but obviously I have a problem. This problem is these PC's cannot access the main database. The main database user has privileges that allow him to alter the database but the other uses that are located in the access points to do not have this privilege. All they can do it enter their username and password and see the data from the database been displayed on the datagrid view.
So my question is how do I grant access to these other three PC's to access the main database?
MySQL Workbench and MySQL server is so far only installed on my laptop and not on the other 3 PC's.
Database users
Error message
The entire point of database technology is to allow multiple clients to access the same server and share the same data. (Actually there's another point: the ability to handle vast amounts of data. But that's not your problem right now.)
Here's what you need to do.
Get MySQL server software set up on a server in your server room. Find out the hostname of that server.
Log in to that server using MySQL Workbench. It asks you for the hostname.
Use Workbench to migrate your data from your localhost MySQL server to the one in the server room. Workbench has decent features to help you do that.
Create a mysql account on the shared server that just has access to the database you just created. Keep in mind that MySQL users look like this: 'david'#'localhost' or 'david'#'*' or 'mickey'#'*.animation.disney.com'. That is, they specify both the username and the machine the user runs on.
Change your C# connection string to mention the shared server's hostname and the account you just created.
myConnectionString = "server=shared.example.com;uid=root;pwd=12345;database=test";
Somehow tell the other users of your app to use this connection string.
There's another, simpler but less robust, way to do all this. Make sure your laptop has its own hostname. I dunno, david.example.com maybe? Ask your local LAN or VPN administrator. Or just use your laptop's IP address in place of a hostname. Then put that hostname into your connection string. Then other users of your application can hit the MySQL server on your laptop. But, if you switch off your laptop and take it home they'll lose access.
Related
I created a desktop application which runs with SQL Database. In my machine installation runs perfect. When installing in other machines it do not. Message is:
Cannot open database “verticaladminmod” requested by the login. The login failed. Login failed for “Fina-PC\Fina”
My machine:
Name “MI_PC-PC”
Owner: “MI_PC-PC\MI_PC”
Database: “verticaladminmod”
Connection string:
Data Source=localhost;Initial Catalog=verticaladminmod;Integrated Security=True
Windows 7 64 bit
SQL Server 2014 Express, instance “SQL Server (MSSQLSERVER)”
Other machine installation:
Name “FINA-PC”
User Name: “Fina-PC\Fina”
Windows 7 32 bit
SQL Server 2012 Express, instance “SQL Server (MSSQLSERVER)”
Already understand it should be a matter of credentials, but after several attempts could not get to make it work. Need specific orientation with detailed steps if possible in order to configure where needed looking forward to resolve this issue and understand it in depth as well. Thank you so much!
First, the connection string needs to point at the correct machine (FINA-PC rather than localhost). In some cases you need an instance there, as well (ie FINA-PC\MSSQLSERVER), but with the default instance you can skip the instance name. This is why localhost worked in the original connection string.
Once that is fixed, we can talk about authentication. If you want integrated security to work across machines you also want to have an Active Directory domain. If you don't have an Active Directory domain, you want to switch to SQL authentication.
SQL authentication requires you to create a user ("login", in Sql Server parlance) in the database with it's own username and password you can put in the connection string. Do not use the sa account for this. You must also then be very careful with how you store the connection string, or any decompiler will show the credential and provide full access to your DB. Once you have the new login and connection string, you must also grant permissions for the account to do the operations you need within your database.
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
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 am pretty new to SQL and I'm stuck on something which is probably a few clicks away.
The program I am building will store the data in the database created on the management studio. Everything works fine on a test application. Now the question is: how should I connect to the database if I want to open the program from another computer? I tried copying the test project on a friend's computer but it cannot find the database as I suppose is obvious because the db is stored on my pc.
i know hundreds of questions like this exist around google but I'm sick of looking at forums reading complicated stuff. any help will be really appreciated.
thanks.
In the database connection settings or script you propably have database server set to 'localhost'
Try setting this to the computer network IP if the other computer is inside the same network.
To connect to it from outside the network (over the internet) You need set the database server setting to you external IP and you have to port-forward (NAT) the SQL server port to your computer.
If you can tell us what database software you are using for the Database I can tell you what port to forward, for more help with forwarding you should ask on serverfault.com and also provide your router/firwall make and model
It depends (at least partly) on how you're connecting to the database in the first place. Normally, you'll have some sort of connection string that tells what computer to connect to. It'll be set to the local computer by default, but changing it to something else is normally just a matter of editing that machine name into the string.
If you're connecting via ODBC, the program will just specify an ODBC connection, and the ODBC connection will specify the machine to connect to. You can use the "Data Sources (ODBC)" control panel to edit these (depending on the version of Windows you're using, it may be in the "Administrative Tools" folder instead of showing up directly in the control panel).
when you want to connect to a sql server over the network there are a few things you should know/check:
is your connection string correct (not localhost)
does the remote sql server accept tcp/ip connections
does the firewall of the remote compture allow the connection
Is the sqlbrowser running on the remote computer (if not you need to specify the port in your connection string.
To make sure this al works the best thing you can do is try to connect from the new pc to the remote database using sql management studio or if you don't want to install the ssms you can try to create an odbc profile that connects to the remote pc. By doing this you can determine if the problem is with the database itself or with your application.
I want to do system to control other machines in LAN. I need here a database, but it should be one database for all computers. I hope it's possible to have installed SQL Server only on chosen machine and connect from others to him over LAN?
Or make db on each comp and synchronise fom time to time with main db?
YES OF COURSE!!
That's the whole point of a database server....
You install a SQL Server version on your server machine, and any number of clients in your LAN can connect to it, read data from it, store data on it.....
Since you're in a LAN environment (inside a company), I would recommend using Windows authentication (the user names people are logged into Windows with) as your security mechanism. You can easily configure certain Windows users (or Windows groups) to have access to your SQL Server (and others are locked out).
Once you have set up your database server, your client apps can connect to it using a connection string something like this:
server=(server-name);database=(your database name);integrated Security=SSPI;