944,030 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 28862
  • VB.NET RSS
Oct 19th, 2005
0

OleDbConnection

Expand Post »
I need urgent help please!!!!

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

Here is my imports:
VB.NET Syntax (Toggle Plain Text)
  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:
VB.NET Syntax (Toggle Plain Text)
  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:

VB.NET Syntax (Toggle Plain Text)
  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 **************
Reputation Points: 10
Solved Threads: 0
Newbie Poster
madelein is offline Offline
4 posts
since Oct 2005
Oct 21st, 2005
0

Re: OleDbConnection

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

Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Nov 23rd, 2005
0

Re: OleDbConnection

Sorry but it still does not work. Still get the same error
Reputation Points: 10
Solved Threads: 0
Newbie Poster
madelein is offline Offline
4 posts
since Oct 2005
Nov 23rd, 2005
0

Re: OleDbConnection

Could this problem occur because of an Incorrect ODBC setup?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
madelein is offline Offline
4 posts
since Oct 2005
Nov 28th, 2005
0

Re: OleDbConnection

Can you provide me more information on this matter?

johntvery@operamail.com

johntvery@hotmail.com
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ralfsmith is offline Offline
1 posts
since Nov 2005
Dec 2nd, 2005
0

Re: OleDbConnection

If the database (the Access DB) set with a password? Meaning when you double click on the file, does it request a password?
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Dec 6th, 2005
0

Re: OleDbConnection

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
madelein is offline Offline
4 posts
since Oct 2005
Nov 8th, 2008
0

Re: OleDbConnection

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bruce2424 is offline Offline
23 posts
since Jun 2008
Nov 18th, 2008
0

Re: OleDbConnection

Quote ...

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

Quote ...

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
Reputation Points: 10
Solved Threads: 9
Junior Poster
sierrainfo is offline Offline
144 posts
since May 2008
Feb 20th, 2009
0

Re: OleDbConnection

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Abhay Joshi is offline Offline
1 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: add, save records using binding navigator
Next Thread in VB.NET Forum Timeline: data extraction





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC