Recent

Author Topic: [HELP] Connecting to a SQL - Console Application  (Read 34527 times)

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL - Console Application
« Reply #30 on: December 17, 2014, 11:48:34 pm »
Also, I won't be able to host this on my PC as I want it dedicated. So I'll have to buy a SQL server

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL - Console Application
« Reply #31 on: December 18, 2014, 12:00:42 am »
So all in all I need to get the username@domain and the dll file and it should work?
You would need to add 'a3762836'@'you_own_hostname' to the user table in the mysql installation and grant the necessary access. You can do that with your own installation of MySQL but you can't do this at a MySQL-provider. They just don't allow that. And 000webhost completely disables remote access for their free accounts.

A few questions.
1) When I compile the exe and send it to a friend they wont need the dll file will they?
2) What hosting are you using for the SQL? I want touse the same as it sounds easier
3) I have no idea how to add username@myhost and stuff

Sorry.
  • Yes, he does need the libmysql.dll too. So you need to send both files.
  • I don't have any open MySQL-connections to the internet. I have my own server for my internal network. My internal webpages (which a can host to the internet if i wanted to) access the locally installed MySQL-installation. My professional website is hosted by an internet provider. The MySQL-access there is also blocked and only accessible from their server (i.e. my professional website)
  • You can only add the user@host with your own MySQL-installation. Others will never let you have access to it because it would be a security breach.
(no need to be sorry, i'm happy to explain it)

So... you have 4 options:
  • Depending on what the program needs to do... you could create this in PHP (instead of Lazarus) and let the users go to your webpages at 000webhost where they interact with those pages.
  • You can install your own MySQL-server and allow port 3306 for MySQL through your router to your PC. Your PC would need to be on for others to access your MySQL-server. You could use Xamp or Wamp for a complete and easy to install solution for a web and MySQL-installation
  • Like option 1... you could create webpages (instead of a Pascal-program) and host them yourself on your own computer. For this options your computer also needs to be on when they want to access the pages and you can use the same Xamp or Wamp installation as option 2. In this case you wouldn't forward port 3306 but port 80 to your own computer.
  • You can look for another MySQL-provider which allows external access. There are a few but I'm not sure what their quality is.

O... yeah... option 5.... pay for access to a MySQL-server  :) In that case they usually have an option for remote access. But always check beforehand. And if your program runs at multiple locations you need to make sure you have access from all those (or all) locations.

Your choice would all depend on what kind of program it is and who uses it.

Could I use this??

http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely

Host gator says you can access it remotely. Does this mean this SQL database will work? It says about just adding IPs. I want it accessed to everyone. Or should I upgrasd my 000webhosting account?
« Last Edit: December 18, 2014, 12:04:18 am by nobodyknowsme »

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: [HELP] Connecting to a SQL - Console Application
« Reply #32 on: December 18, 2014, 12:08:20 am »
Yes, if it is a game for which the MySQL connection always need to be present hosting it yourself would not be practical (unless you have an old PC and a dedicated internet connection).

If the game is still in development you could try some of the free MySQL-providers and see how their quality are.
(search for free mysql hosting with external access)

If in the end there is a lot of money involved and the game needs to "grow" it's best to choose for a professional (paid) option. Just make sure the database is accessible from everywhere and not that you need to add a host to the settings each time for it to be allowed.

B.T.W. if it's only for login and/or small communication packages (i.e. scoring etc.) you could also create a small interface in PHP on any given website. That PHP would have local access to the MySQL-database because it is hosted on the same machine. (every website provider with a MySQL-database option will do in that case)


Host gator says you can access it remotely. Does this mean this SQL database will work? It says about just adding IPs. I want it accessed to everyone. Or should I upgrasd my 000webhosting account?
Adding IP manually wouldn't be practical in your case. If that's the only access they allow it won't work. I'm not sure if 000webhosting does the same. (That's why I said above you needed to make sure they allow "wildcard"-hostname access, I'm not even sure there are any with that kind of access)
« Last Edit: December 18, 2014, 12:10:20 am by rvk »

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL - Console Application
« Reply #33 on: December 18, 2014, 12:14:08 am »
Wait so my pho script could store the logins and could access it from there? That sounds like a good idea. How would I go about doing that? Or shall I just use hosting with external SQL. I've looked at some websites and not to be lazy however could you look and find a website that allows the SQL external database? If you see an okay one link me? Thank you so much. I would be so stuck without you. :)

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: [HELP] Connecting to a SQL - Console Application
« Reply #34 on: December 18, 2014, 12:28:55 am »
Wait so my pho script could store the logins and could access it from there? That sounds like a good idea. How would I go about doing that? Or shall I just use hosting with external SQL. I've looked at some websites and not to be lazy however could you look and find a website that allows the SQL external database? If you see an okay one link me? Thank you so much. I would be so stuck without you. :)
When looking for MySQL-providers you need to add the term "wildcard" to your search. This is one I found quite easily:
http://www.inmotionhosting.com/support/website/databases/setting-up-a-remote-mysql-connection-in-cpanel#wildcard
But now I'm sure there are more.
(Can't speak about the reliability of that provider as they are unknown to me)

Hey... I even found hostgator does accept wildcards for MySQL :)
http://support.hostgator.com/articles/cpanel/how-to-whitelist-your-ip-in-cpanel-for-remote-mysql-access

Quote
Note: If you're connecting from a dynamic IP address, you can use the "%" wildcard value instead of an IP address.  However, since this will grant access from anywhere, it is generally considered a security risk and therefore not recommended.

And for the PHP script: The PHP-script itself wouldn't even need to store it but interact with the local MySQL database. Simple example of a call to a PHP for adding a user:
http://www.yourdomain.com/game.api/add_user.php?user=me&password=secret

Checking for a user:
http://www.yourdomain.com/game.api/check_user.php?user=me&password=secret
This php-script could search in the MySQL-database is user me exists and if password is secret. It could echo correct or incorrect back.

This is just a very simple example and easily hackable so there would need to be some security build in that you are sure the answer is from your domain.

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL - Console Application
« Reply #35 on: December 18, 2014, 08:52:51 am »
What do you mean wild card? Also for security issues I won't use the php script.thank you!

minesadorada

  • Sr. Member
  • ****
  • Posts: 452
  • Retired
Re: [HELP] Connecting to a SQL - Console Application
« Reply #36 on: December 18, 2014, 10:20:21 am »
I have a Lazarus app that connects to freemysqlhosting.net successfully.

For the free account, you have to verify it each week, but they also offer paid hosting.
GPL Apps: Health MonitorRetro Ski Run
OnlinePackageManager Components: LazAutoUpdate, LongTimer, PoweredBy, ScrollText, PlaySound, CryptINI

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL - Console Application
« Reply #37 on: December 18, 2014, 10:26:10 am »
Okay, does it allow wild cards? And will it allow my to create a username@database?

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL - Console Application
« Reply #38 on: December 18, 2014, 10:28:21 am »
Okay, does it allow wild cards? And will it allow my to create a username@database?

Will it connect though a table so that it can match someones username and password in theory?

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL - Console Application
« Reply #39 on: December 18, 2014, 10:36:58 am »
I have a Lazarus app that connects to freemysqlhosting.net successfully.

For the free account, you have to verify it each week, but they also offer paid hosting.

minesadorada or rvk

It still wont work though it? As its open and free I have left the password in this one.
It breaks at AConnection.Open again. Any ideas why?

Code: [Select]
program project1;

uses
  sqldb, mysql41conn;

var
  AConnection: TSQLConnector;

  procedure CreateConnection;
  begin
    AConnection := TSQLConnector.Create(nil);
    //AConnection.ConnectorType := 'MySQL 4.1';
    AConnection.Hostname := 'sql5.freemysqlhosting.net';
    AConnection.DatabaseName := 'sql561707';
    AConnection.UserName := 'sql561707';
    AConnection.Password := 'dX3%eP3!';
  end;

begin
  CreateConnection;
  AConnection.Open;
  if Aconnection.Connected then
    begin
    writeln('Successful connect!');
    readln
    end

  else
    writeln('This is not possible, because if the connection failed, an exception should be raised, so this code would not be executed');
  AConnection.Close;
  AConnection.Free;

  readln;

end.


minesadorada

  • Sr. Member
  • ****
  • Posts: 452
  • Retired
Re: [HELP] Connecting to a SQL - Console Application
« Reply #40 on: December 18, 2014, 10:41:51 am »
Okay, does it allow wild cards? And will it allow my to create a username@database?

It´s a standard MySQL v5.6 server.  You get one database, with as many tables as you like.  There is one master login, and a CPanel to manage your database.  Check out their website to see if it has restrictions that would be a problem for your app.

My app uses mysql56conn and a TMySQL56Connection object to connect to it

http://www.freemysqlhosting.net/
GPL Apps: Health MonitorRetro Ski Run
OnlinePackageManager Components: LazAutoUpdate, LongTimer, PoweredBy, ScrollText, PlaySound, CryptINI

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL - Console Application
« Reply #41 on: December 18, 2014, 10:50:33 am »
COuld I have your code as an example at all? At the moment this doesn't work. ANy ideas why? I created a random table called users.

Code: [Select]
program project1;

uses
  sqldb, mysql41conn;

var
  AConnection: TSQLConnector;

  procedure CreateConnection;
  begin
    AConnection := TSQLConnector.Create(nil);
    AConnection.ConnectorType := 'MySQL 5.6';
    AConnection.Hostname := 'sql5.freemysqlhosting.net';
    AConnection.DatabaseName := 'sql561707';
    AConnection.UserName := 'sql561707';
    AConnection.Password := 'dX3%eP3!';
  end;

begin
  CreateConnection;
  AConnection.Open;
  if Aconnection.Connected then
    begin
    writeln('Successful connect!');
    readln
    end

  else
    writeln('This is not possible, because if the connection failed, an exception should be raised, so this code would not be executed');
  AConnection.Close;
  AConnection.Free;

  readln;

end.

minesadorada

  • Sr. Member
  • ****
  • Posts: 452
  • Retired
Re: [HELP] Connecting to a SQL - Console Application
« Reply #42 on: December 18, 2014, 10:59:38 am »
COuld I have your code as an example at all? At the moment this doesn't work. ANy ideas why? I created a random table called users.

Code: [Select]
program project1;

uses
  mysql56conn;

var
  Aconnection: TMySQL56Connection;

  procedure CreateConnection;
  begin
    Aconnection:=TMySQL56Connection.Create(Nil);
    AConnection.Port:=3306;
    AConnection.Role:='User';
    AConnection.Hostname := 'sql5.freemysqlhosting.net';
    AConnection.DatabaseName := 'sql561707';
    AConnection.UserName := 'sql561707';
    AConnection.Password := 'dX3%eP3!';
  end;

begin
  CreateConnection;
  AConnection.Open;
  if Aconnection.Connected then
    begin
    writeln('Successful connect!');
    readln
    end

  else
    writeln('This is not possible, because if the connection failed, an exception should be raised, so this code would not be executed');
  AConnection.Close;
  AConnection.Free;

  readln;

end.

Here are some changes that may help  (code is untested)
« Last Edit: December 18, 2014, 11:01:17 am by minesadorada »
GPL Apps: Health MonitorRetro Ski Run
OnlinePackageManager Components: LazAutoUpdate, LongTimer, PoweredBy, ScrollText, PlaySound, CryptINI

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL - Console Application
« Reply #43 on: December 18, 2014, 11:05:50 am »
It still breaks at  AConnection.Open. When this happened last time it meant it wasn't connecting properly. I've entered all the details correctly.

minesadorada

  • Sr. Member
  • ****
  • Posts: 452
  • Retired
Re: [HELP] Connecting to a SQL - Console Application
« Reply #44 on: December 18, 2014, 11:08:38 am »
Does your router have the port 3306 open to the internet?  Is an AV interfering with the port access?

What is the exception raised?  There is no code to trap it in your example.
GPL Apps: Health MonitorRetro Ski Run
OnlinePackageManager Components: LazAutoUpdate, LongTimer, PoweredBy, ScrollText, PlaySound, CryptINI

 

TinyPortal © 2005-2018