Search code examples
c#databasevisual-studioconnection

Windows application and database connection


I'm making a windows form application with C# using Visual Studio 2015 and I want to use a database located in other computer which is on another house (I use it as a server, localhost is not an option btw).

I tried to connect it through MySQL Server but I can't get it done.

So my question is, can it be done? If yes, which database language/server would you use on my scenario? And maybe a little bit of explanation if you can.


Solution

  • Well, you seem to be having several problems there, and your question is quite broad. Anyway, I´ll give you some pointers that have to be covered to make it work. If you follow each and everyone of them, you should get the things working. I´ll assume that you use SQL Server, buy I have my doubts since you said MySQL Server. Anyway if you use MySQL this will help you too:

    • If the database is in another location (another house, as you say), then you probably are not on the same VLAN. Tell your friend to publish the SQL Server port on his router and redirect to his computer, and that way you´ll have to access SQL Server through the public IP. This is not the best idea anyway, I never liked publishing database servers over the internet. But in your case it will get the things working.
    • Enable all networking functionality on Sql Server Configuration Manager. By this, I mean to enable all TCP/IP settings so you can access from anywhere on your network. Here is a link of how to do it. Basically you will enable the protocol and all the IP´s you wanna access SQL Server through. https://msdn.microsoft.com/en-us/library/ms177440.aspx
    • Be sure to be using a SQL Server login. If you are working through internet, you won´t be able to use a Windows Login. Also, check SQL Server to be configured as mixed login (Windows and SQL).
    • Always check first with Sql Server Management Studio and then when you connect, use the same parameters to your connection string. It is easier to test with management studio than with your app.