Remote SQL Connection

Arda

New member
Joined
Jul 19, 2010
Messages
2
Programming Experience
Beginner
Hi guys,
I'm not sure if I posted this in the right area but here goes. I want to connect to a SQL Database remotely located on my website (eg. abc.net) and this is the code I am using
VB.NET:
Imports System.Data.SqlClient

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

Dim connection As SqlConnection

        connection = New SqlConnection()

 

        connection.ConnectionString = "Server=abc.net; Uid=abc_username; Pwd=password; Database=abc_db;"



        Try

            connection.Open()

            MessageBox.Show("Connection Opened Successfully")

            connection.Close()

        Catch mysql_error As SqlException


            MessageBox.Show("Error Connecting to Database: " & mysql_error.Message)

        Finally

            connection.Dispose()
        End Try
I have enabled remote connection on the server and I can connect to it using TOAD. Any help would be appreciated
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,322
Location
Sydney, Australia
Programming Experience
10+
First up, Remoting is a specific .NET technology for communication between applications and has nothing to do with remote connections to SQL Server. I've moved your thread to a more appropriate forum.

As for the question, allowing remote connections means that you can connect from other machines on the same network, i.e. LAN or WAN. Connecting over the internet is something else, and would require you to configure SQL Server to allow HTTP connections. It's not something I've ever done so I can't give you details, but it's something for you to investigate. Also, I think you'll find that it's not done much at all because it's considered a security risk. More often, the data will be exposed via a web service, so the database itself is not accessible from outside and you can keep access restricted as much as possible.
 

Arda

New member
Joined
Jul 19, 2010
Messages
2
Programming Experience
Beginner
jmcilhinney, thank you for your prompt reply and your words of wisdom. However I am curious to know how do applications authenticate the correct users, for example, live messenger. You need a user name and password right? You enter your credentials into the application (email address and password) and the application then compares the given credentials to a database located on server over the internet. Maybe I wasn't specific with my original post, but I basically need to connect to my database over the Internet and I am sure there is a secure way of doing this, nevertheless does anyone know how to do this with vb.net?
Cheers
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
Apps that work like that usually either:

Connect to the database directly or via a VPN for extra security

Conenct to an established service whose only purpose is to expose certain functions of the database - this is often called a web service (a web site intended for use by computers, not humans)
 
Top Bottom