vb.net reconnecting lost connection automatically to mysql server - vb.net-2010

Any idea on reconnecting lost connection automatically using vb.net (windows form) to mysql server.
I am planning to develop an application. To be specific, it is a timer for an internet cafe.
The case is if the server downloaded some updates and need to restart, the client pc will reconnect automatically when the server boot up. Any idea? Thanks
I'm using this code to connect:
Dim DatabaseName As String = "xxx"
Dim server As String = "xxx"
Dim userName As String = "xxx"
Dim password As String = "xxx"
If Not conn Is Nothing Then conn.Close()
conn.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password, DatabaseName)
Try
conn.Open()
MsgBox("Connected")
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()

Related

Getting Login failed for user ~NT AUTHORITY\ANONYMOUS LOGON~ after upgrading to .NET 4.0

Getting Login failed for user ~NT AUTHORITY\ANONYMOUS LOGON~ after upgrading to .NET 4.0
a few seconds ago|LINK
I have a visual 2005 web application (version .NET 2.0). I am able to login to the database and open a connection. I upgraded my project to .NET 4.0 and ran the same project again. After I enter my userId, I get the "Login failed for user ~NT AUTHORITY\ANONYMOUS LOGON~" error. I am not sure what is causing the error. When it gets to the con.Open() line, it throws an exception. Any help is appreciated.
Public Shared Function GetUserMenuItems(ByVal userId As String) As DataTable
Dim dt As DataTable
Dim con As SqlConnection = Db.DataAccess.GetAdminSqlConnection()
Dim cmd As New SqlCommand("uspGetUserMenuItems", con)
With cmd
.CommandType = CommandType.StoredProcedure
With .Parameters
.Add("#UserID", SqlDbType.VarChar, 80).Value = userId
End With
End With
Try
con.Open()
dt = Db.DataAccess.GetDataTable(cmd, "Validations")
Return dt
Catch err As Exception
Throw err
Finally
con.Close()
con.Dispose()
cmd.Dispose()
End Try
End Function
Connection string is
Your username and password should be in your connection string. You are passing the userid as a parameter, the open connection needs the correct configuration to open the connection in the first place.

Can not connect to a SQL Server express database with VB.net

I am attempting to connect to a SQL Server Express Database through VB.net. As I run my connect string I am getting an error. Here is the code that I am using to connect. It works fine for another SQL Server database, however it errors out with the sql server express database.
Imports System.Data
Imports System.Data.SqlClient
Public sqlCnn As SqlConnection
Dim strCONN As String = "Data Source=CAFS\ADEMERO;Initial Catalog=OurDB;User ID=sa;Password=PASSWORD1!"
Try
sqlCnn = New SqlConnection(strCONN)
sqlCnn.Open()
Return True
Catch ex As Exception
MessageBox.Show(ex.Message,
"Content Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return False
End Try
Any assistance you can lend would be a great help.

Problems with DataAdapter at VB.Net in a connection to SQL Server 2008

I´m experimenting troubles on a local connection to SQL Server 2008, it´s throwing me the next especific error:
A network-related or instance-specific error ocurred while establishing a connection to SQL Server. The server was not found or was not accesible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections (error 40)
I´ve tried with most of solutions concerning to SQL Services and Firewall Solutions, so i think the problem is specific in the source code, so it is:
Private Sub cargar_Combo(ByVal ComboBox As ComboBox, ByVal sql As String)
Dim strConexion As String = "Data Source=Angel-PC\SQLEXPRESS1;Initial Catalog=sistemaReferencias;Integrated Security=True"
Dim conexion As New SqlConnection(strConexion)
Try
conexion.Open()
Dim cmd As New SqlCommand(sql, conexion)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
ComboBox.DataSource = ds.Tables(0)
ComboBox.DisplayMember = ds.Tables(0).Columns(1).Caption.ToString
ComboBox.ValueMember = ds.Tables(0).Columns(0).Caption
Catch ex As Exception
MessageBox.Show(ex.Message.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If conexion.State = ConnectionState.Open Then
conexion.Close()
End If
End Try
End Sub
I know that the String connection is right, because i used it in another method, the error comes specifically at the "da.Fill(ds)" line, those are the basics
I really appreciate any help you can provide.
Go to your desktop. Right click and add a new text file, "test.txt".
Rename the text file to test.udl, you will get a warning, just accept it.
Double click test.udl, and you will have an interactive dialog to configure your connection string.
Once you have configured the connection string. Click save. The right click the test.udl file and open in notepad. This will give you the connection string that you need to put into your app.

Connecting to local sql server in vb.net - Error Connecting and difference between Local and Commercial?

I am a developer building websites in VB.Net using Visual Studio 2010. I am trying to populate some fields when a user visits a website based on their decisions on a previous screen.
My connection information is as follows:
Dim myDataReader As SqlDataReader
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim strSQL As String
myConnection = New SqlConnection("Data Source=localhost\sqlexpress; Database=PREP; Integrated Security=SSPI;")
Try
myConnection.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try
strSQL = "SELECT * FROM Charts where ID=1"
myCommand = New SqlCommand(strSQL, myConnection)
myDataReader = myCommand.ExecuteReader()
If myDataReader.Read() Then
TextBox1.Text = myDataReader.Item("Priority1")
Else
MsgBox("Didn't work...")
End If
The error I continue to get is:
Cannot open database "PREP" by the login. The login failed. Login failed for user 'OR-AA-Me\Me'
I assumed that since it was a local database I would not need a username and password. Am I wrong?
Also, are there glaring practices in the above code that will be unwise when I transport this to a commercial environment?
Thanks!
Solved:
The connection string simply needed additional filepath information.
The successful connection information was:
myConnection = New SqlConnection("Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\PREP.mdf; Integrated Security=True; User Instance=True")
There was no need for a username as the Integrated Security set to True assumes that the computer will use the login information for the user on the actual computer he is using.

data source name not found

trouble connecting to postgresql database using odbc connector(x64) on vb.net console application(x64), the error,
http://www.sumarlidason.com/tmp/120312/odbc_capture1.png
Dim ConnectionString = "Driver={PostgreSQL UNICODE};Server=myPGSrv;Port=5432;Database=dbDefault;Uid=postgres;Pwd=pw;"
'Dim ConnectionString = "ODBC;dsn=PostgreSQL35W"
conn = New OdbcConnection(ConnectionString)
'Open connection to an instance of the PostgreSQL database.
Try
conn.Open()
Catch Ex As Exception
MsgBox(Ex.Message)
End Try
Dim commonOdbcCommand = New OdbcCommand
commonOdbcCommand.Connection = conn
conn.Close()
Also, I configured the database in the control panel, see here..
http://sumarlidason.com/tmp/120312/odbc_capture.png
correct connection string:
Dim conn As New OdbcConnection("DSN=PostgreSQL35W")