data source name not found - vb.net

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")

Related

how to connect vb.net thorgh online phpmyadmin

Dim conn As MysqlConnection
conn = New Mysqlconnection()
conn.ConnectionString = "server=justhost.com; user id=*****; password=****; database=login"
Try
conn.Open()
Catch myerror As MySqlException
MsgBox("Error connecting to database!")
End Try
this code not working ? how to connect online phpmyadmin database use vb.net?
Have you tried installing this one?
http://dev.mysql.com/downloads/connector/net/
and after installing that, try to reconfigure your code try this.
Imports MySql.Data.MySqlClient
Dim Connection As MySqlConnection = New MySqlConnection()
Dim ConnectionString As String = "Server=SERVERNAME or the Database online link;Database=DATABASE;Uid=root;Pwd=password;"
Connection.ConnectionString = ConnectionString
Connection.Open()
//Execute here what ever you want just follow your heart <3
myConnection.Close()

VB.NET - Key word is not supported: provider

When I try to connect to AcessDB, I get the error
"Keyword is not supported: provider".
When I try to change provider, I get another error. When I delete provider tag, I also get an error.
Dim Exists As Boolean = False
Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Name\Documents\Visual Studio 2010\Projects\datagrid\datagrid\pokus.accdb;Persist Security Info=False;"
Dim connection As New SqlConnection(ConnectionString)
Try
connection.Open()
Dim command As SqlCommand = connection.CreateCommand
command.CommandText = "SELECT * FROM studenti"
Dim reader As SqlDataReader = command.ExecuteReader
If reader.HasRows Then
Exists = True
Else
Exists = False
End If
reader.Close()
command.Dispose()
Catch ex As Exception
Console.Write(ex.Message)
Finally
connection.Close()
End Try
SqlConnection, SqlCommand, etc. are SQL Server-specific classes. You can't use them to connect to MS Access.
The documentation for SqlConnection makes this very clear:
Represents an open connection to a SQL Server database.
Consider using the OldDbConnection and related classes instead.
I always write wrapper classes for database connections, and I always recommend the same.
Dim sConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Name\Documents\Visual Studio 2010\Projects\datagrid\datagrid\pokus.accdb;Persist Security Info=False;"
Dim Conn As New OleDbConnection
Conn.ConnectionString = sConnectionString
Conn.Open()
Dim sQuery As String = "SELECT * FROM studenti"
Dim da As New OleDbDataAdapter(sQuery, Conn)
Dim dt As New DataTable
da.Fill(dt)
Conn.Close()

Oledb Connection Hangs VB.Net

I am using an OledbConnection to an AS400 computer. When I have a SQL statement that will return nothing, it just hangs on the adapter command Fill.
Function ExecuteOLEDBQuery(ByVal cmdtext As String) As DataTable
Try
Dim connString As String = "Provider=IBMDA400;Persist Security Info=True;User ID=##USERID;Password=##PASSWORD;Data Source=##SYSTEM"
Dim as400 As New OleDb.OleDbConnection(connString)
Dim cmd As New OleDb.OleDbCommand(cmdtext, as400)
Dim adapter As New OleDb.OleDbDataAdapter(cmd)
cmd.CommandTimeout = 60 'Doesn't work. It never times out.
Dim dt As New DataTable
as400.Open()
adapter.Fill(dt) 'This is where it hangs
as400.Close()
adapter.Dispose()
cmd.Dispose()
Return dt
Catch ex As Exception
Return Nothing
End Try
End Function
Any ideas?
It may be the connection to the AS400 itself. Try this version which disposes of the object in a slightly different order:
Function ExecuteOLEDBQuery(cmdtext As String) As DataTable
Using cn = New OleDbConnection("Provider=IBMDA400;Persist Security Info=True;User ID=##USERID;Password=##PASSWORD;Data Source=##SYSTEM")
cn.Open()
Using da = New OleDbDataAdapter(cmdtext, cn)
Dim dt = New DataTable
da.Fill(dt)
Return dt
End Using
End Using
End Function

operator/operand type mismatch when update dbf file

i have a program needs to update data in dbf file. but it keeps appear error 'operator/operand type mismatch'. here is sample code :
Dim con As OleDbConnection = New OleDbConnection("Provider=vfpoledb;Data Source=C:\folder\paytran.dbf;Collating Sequence=machine;")
Try
Dim strSQL As String = "UPDATE paytran.dbf SET workhr = 20 WHERE empno = 102"
Dim cmd As OleDbCommand = New OleDbCommand(strSQL, con)
con.Open()
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
' Using DataAdapter object fill data from database into DataSet object
myDA.Fill(myDataSet, "MyTable")
' Binding DataSet to DataGridView
DGV.DataSource = myDataSet.Tables("MyTable").DefaultView
con.Close()
con = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message, "Error Select Data")
Finally
If con IsNot Nothing Then
con.Close()
End If
End Try
please help me..
Its your connection string. The connection string should only have to point to the PATH where the data files are located, then all the SQL based commands will by default be able to see any .DBF tables IN that path (or forward if subpaths exists).
Data Source=C:\folder
instead of
Data Source=C:\folder\paytran.dbf
So, now if you have 30 tables in the "C:\folder", you can now query from ALL of them as needed.
You need to explicitly open and close the DBF. Try:
Dim strSQL As String = "Use paytran in 0 shared;UPDATE paytran SET workhr = 20 WHERE empno = 102;use in select('paytran')"

select data from Dataset Vb.Net

ok first ill explain what ive done.
First I imported an access db into my vb app it then named the dataset etc.
this is how my dataSet looks:
1 table
4 columns
so Far i have this:
Dim ds As ElementsDataSet
Dim dt As ElementsDataSet.ElementsDataTable
Dim conn As SqlConnection = New SqlConnection("Data Source=|DataDirectory|\Elements.accdb")
Dim selectString As String = "Select Atomic Mass FROM Elements WHERE No =" & mol
Dim cmd As New SqlCommand(selectString, conn)
If conn.State = ConnectionState.Closed Then conn.Open()
Dim datareader As SqlDataReader = cmd.ExecuteReader()
While datareader.Read = True
MessageBox.Show(datareader.Item("Atomic Mass"))
End While
datareader.Close()
and upon executing this I get this error:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
The problem is you are using a SQLConnection to open a Access database. This wont work.
You either need a SQLServer database or to use the OleDbConnection for a Access database.
Here is a Microsoft KB article to help you connect to the Access database:
How To Retrieve and Display Records from an Access Database by Using ASP.NET, ADO.NET, and Visual Basic .NET and this one over at CodeProject: http://www.codeproject.com/Articles/8477/Using-ADO-NET-for-beginners
Private Sub ReadRecords()
Dim conn As OleDbConnection = Nothing
Dim reader As OleDbDataReader = Nothing
Try
conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\Elements.accdb"))
conn.Open()
Dim cmd As New OleDbCommand("Select Atomic Mass FROM Elements WHERE No =" & mol, conn)
reader = cmd.ExecuteReader()
While reader.Read = True
MessageBox.Show(reader.Item("Atomic Mass"))
End While
Finally
If reader <> Nothing Then
reader.Close()
End If
If conn <> Nothing Then
conn.Close()
End If
End Try
End Sub