OleDbConnection

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2005
Posts: 4
Reputation: madelein is an unknown quantity at this point 
Solved Threads: 0
madelein madelein is offline Offline
Newbie Poster

OleDbConnection

 
0
  #1
Oct 19th, 2005
I need urgent help please!!!!

This is my problem:
I want to connect to a Access database with VB.Net.

Here is my imports:
  1. Imports System.IO
  2. Imports System
  3. Imports System.Data
  4. Imports System.Data.OleDb
  5. Imports System.Collections
  6. Imports System.ComponentModel

Here is my connection string:
  1. Public pDB As New OleDbConnection("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source='F:\relayMaster.mdb';Jet OLEDB:Engine Type=5;Provider='Microsoft.Jet.OLEDB.4.0';Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1")
  2.  
  3. Public pDataAdapt As New OleDbDataAdapter

Here is my code where i want to access the database:

  1. Private Sub GetTodayScd(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
  2.  
  3. pDSet1.Clear()
  4. pDSet2.Clear()
  5.  
  6. Dim switchOnceSQL As String
  7. switchOnceSQL = "SELECT switchOnce.day, switchOnce.month, switchOnce.year, switchOnce.hour, switchOnce.min, switchOnce.port, switchOnce.state "
  8. switchOnceSQL &= "FROM(switchOnce) "
  9. switchOnceSQL &= "WHERE(((switchOnce.day) = "
  10. switchOnceSQL &= Now().ToString("dd")
  11. switchOnceSQL &= ") And ((switchOnce.month) = "
  12. switchOnceSQL &= Now().ToString("MM")
  13. switchOnceSQL &= ") And ((switchOnce.year) = "
  14. switchOnceSQL &= Now().ToString("yyyy")
  15. switchOnceSQL &= ")) ORDER BY switchOnce.day, switchOnce.month, switchOnce.year, switchOnce.hour, switchOnce.min, switchOnce.port;"
  16.  
  17. Try
  18.  
  19. pDataAdapt.SelectCommand = New OleDbCommand(switchOnceSQL, pDB)
  20. pDataAdapt.Fill(pDSet1, "OnceOff")
  21.  
  22. Catch ex As OleDbException
  23.  
  24. MessageBox.Show("Connection to Database Failed", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  25. Return
  26.  
  27. End Try
  28.  
  29. Dim scheduleSQL As String
  30. scheduleSQL = "SELECT schedule.day, 0 AS [month], 0 AS [year], schedule.hour, schedule.min, schedule.port, schedule.state "
  31. scheduleSQL &= "FROM(schedule) "
  32. scheduleSQL &= "WHERE (((schedule.day)="
  33. scheduleSQL &= Now().DayOfWeek()
  34. scheduleSQL &= ")) ORDER BY schedule.day, schedule.hour, schedule.min, schedule.port;"
  35.  
  36. Try
  37.  
  38. pDataAdapt.SelectCommand = New OleDbCommand(scheduleSQL, pDB)
  39. pDataAdapt.Fill(pDSet2, "Schd")
  40.  
  41. Catch ex As OleDbException
  42.  
  43. MessageBox.Show("Connection to Database Failed", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  44. Return
  45.  
  46. End Try
  47.  
  48. schDGrid1.SetDataBinding(pDSet1, "OnceOff")
  49. schDGrid2.SetDataBinding(pDSet2, "Schd")
  50.  
  51.  
  52. End Sub

and last, here is my error:
Connection to Database Failed

I am stil new to programming and need all the help I can get. Tx a mill :cry:
Last edited by Paladine; Oct 21st, 2005 at 1:25 am. Reason: **** PLEASE USE CODE BLOCKS **************
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: OleDbConnection

 
0
  #2
Oct 21st, 2005
Just off the top of my head your connection string to the DB is far to long , and complicated for what you are doing.

Replace it with this :

"Provider = Microsoft.Jet.OLEDB.4.0;Data Source=F:\relayMaster.mdb;User Id=Admin;Password=;"

And second, you dont put single quotes inside the double quotes, and your may work.

Hope this helps

Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 4
Reputation: madelein is an unknown quantity at this point 
Solved Threads: 0
madelein madelein is offline Offline
Newbie Poster

Re: OleDbConnection

 
0
  #3
Nov 23rd, 2005
Sorry but it still does not work. Still get the same error
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 4
Reputation: madelein is an unknown quantity at this point 
Solved Threads: 0
madelein madelein is offline Offline
Newbie Poster

Re: OleDbConnection

 
0
  #4
Nov 23rd, 2005
Could this problem occur because of an Incorrect ODBC setup?
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 1
Reputation: ralfsmith is an unknown quantity at this point 
Solved Threads: 0
ralfsmith ralfsmith is offline Offline
Newbie Poster

Re: OleDbConnection

 
0
  #5
Nov 28th, 2005
Can you provide me more information on this matter?

johntvery@operamail.com

johntvery@hotmail.com
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: OleDbConnection

 
0
  #6
Dec 2nd, 2005
If the database (the Access DB) set with a password? Meaning when you double click on the file, does it request a password?
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 4
Reputation: madelein is an unknown quantity at this point 
Solved Threads: 0
madelein madelein is offline Offline
Newbie Poster

Re: OleDbConnection

 
0
  #7
Dec 6th, 2005
No, there is no password. The thing is I now get a problem with this statement:

OleDbDataAdapter1.Fill(DsSwitchOnce, "switchOnce")

DsSwitchOnce is the dataset and switchOnce is the tablename

Here is the error message:

An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

Additional information: Fill: SelectCommand.Connection property has not been initialized.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: bruce2424 is an unknown quantity at this point 
Solved Threads: 0
bruce2424 bruce2424 is offline Offline
Newbie Poster

Re: OleDbConnection

 
0
  #8
Nov 8th, 2008
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourdatabasename.mdb;"
connection = New OleDbConnection(connetionString)

full src code

http://vb.net-informations.com/ado.n...connection.htm

bruce
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 144
Reputation: sierrainfo is an unknown quantity at this point 
Solved Threads: 9
sierrainfo sierrainfo is offline Offline
Junior Poster

Re: OleDbConnection

 
0
  #9
Nov 18th, 2008

1st Method


Imports System.Data

Module Test

Sub Main()
Dim sConnectionString, sSQL As String

'SQL Connection String
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\yourdatabase.mdb"

sSQL = "SELECT Title FROM yourTable"

Dim conn As New System.Data.OleDb.OleDbConnection(sConnectionString)
Dim cmd As New System.Data.OleDb.OleDbCommand(sSQL, conn)
Dim dr As System.Data.OleDb.OleDbDataReader
conn.Open()

dr = cmd.ExecuteReader()

Do While dr.Read()
System.Console.WriteLine(dr.Item("Title"))
Loop

dr.Close()
conn.Close()
End Sub
End Module
2nd Method


Dim pagedData As New PagedDataSource

Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
doPaging()
End Sub

Function getTheData() As DataTable
Dim DS As New DataSet()
Dim strConnect As New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=App_Data/ArtDatabase.mdb")
Dim objOleDBAdapter As New OleDbDataAdapter("SELECT ArtID, FileLocation, Title, UserName, ArtDate FROM Art ORDER BY Art.ArtDate DESC", strConnect)
objOleDBAdapter.Fill(DS, "Art")

Return DS.Tables("Art").Copy
End Function

Sub doPaging()
pagedData.DataSource = getTheData().DefaultView
pagedData.AllowPaging = True
pagedData.PageSize = 2

Try
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
Catch ex As Exception
pagedData.CurrentPageIndex = 0
End Try

btnPrev.Visible = (Not pagedData.IsFirstPage)
btnNext.Visible = (Not pagedData.IsLastPage)

pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount

ArtRepeater.DataSource = pagedData
ArtRepeater.DataBind()
End Sub
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1
Reputation: Abhay Joshi is an unknown quantity at this point 
Solved Threads: 0
Abhay Joshi Abhay Joshi is offline Offline
Newbie Poster

Re: OleDbConnection

 
0
  #10
Feb 20th, 2009
Hi,

Try by not opening the connection in declaration.

===================================
dim conn as OleDbConnection
conn = New OleDbConnection
conn.ConnectionString = sConnectionString
conn.Open()
===================================

Some time opening connection in declaration works but sometimes you need to open it seperately. I suppose this is a bug in OldDb but not sure why and when it fails.

Regards

Abhay
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC