Question

I have been working on this for a few days now. I am trying to make vb.net forms app for my database. Right now I am working on a login form and a main form. I have researched many different websites and played with this string forever, but i can not get a connection to my db. I get different errors saying the machine refused it, then ill get a timeout error, then it will go back to refusal.

Dim conn As New MySqlConnection
    If conn.State = ConnectionState.Closed Then
        conn.ConnectionString = ("Server=192.168.0.2;Database=Sunshinetix;User=sa;Password=sunshine;")
    End If

Can someone please tell me what I am doing wrong? I am a beginner in vb.net. And this is a remote server, but LAN.

Thanks!

PS: Is is because I am using SQL Express?

Enable remote connections for SQL Server Express 2012

I've had that article open for a few days and it has helped me a lot to this point.

Was it helpful?

Solution

If you are using Sql Server express, you need to use a SqlConnection, not a MySqlConnection. That one is for use with MySQL, which is a different implementation of SQL than Microsoft SQL Server

Of course, Microsoft also offers the OleDbConnection as kind of a "catch-all" (see more here: Difference between Sql Connection and OLEDB Connection). Still, if I know I'm going to stick with a particular SQL provider, then I generally use the specialized version.

Also, if you're ever interested, here is a small list of common SQL providers:

  • Microsoft SQL Server - proprietary SQL provider developed and supported by Microsoft
  • MySQL - Free, open source relational database system developed by Oracle. Very popular with web developers.
  • PostgreSQL - another open-source RDBMS. Gaining popularity due to its flexibility and adherence to standards.
  • SQLite - a small, SQL provider with an emphasis on portability. Unlike the others, it uses local database files rather than a remote server. This has made it pretty much the default choice when developing mobile applications that require local storage.

OTHER TIPS

Try this:

Dim SQLConn As SqlConnection = New SqlConnection
SQLConn.ConnectionString = "Data Source=servername;" & _
"Initial Catalog=databasename;" & _
"User ID=username;" & _
"Password=userpassword;"

The reason why you can't connect is that you are using MySQLConnection that is connectiong to connecting to MySQL DB which is different from MS SQL so you need to use SqlConnection

You might also check this:

http://support.microsoft.com/kb/308656

Also check this site:

http://www.connectionstrings.com/sql-server/

To know preferences of your SqlConnection string according to SQL version.

Try this to test your connection string:

    Dim connectString as String = ""
Try
     Dim objConn As SqlConnection = New SqlConnection(Server=192.168.0.2;Database=Sunshinetix;User=sa;Password=sunshine;)
     objConn.Open()
     objConn.Close()
     Msgbox("Successfully connected to database!")
Catch ex As Exception
     Msgbox("Cannot connect, Error:" & ex.Message)
End Try
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top