.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 13th, 2005, 03:41 PM
zombie_man23 zombie_man23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 22 zombie_man23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 16 m
Reputation Power: 0
Calling MS Access Connection String problem

I have the connection string located in a common.vb file in my asp.net solution. The connection string looks like this:

Public Function dbConn()
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Documents an" & _
"d Settings\EZ\Desktop\PurdueAlumni.mdb"
Dim strConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )

dbConn = strConnection
End Function

This is what I have in a form that needs to call the connection string:

Dim dbConnection As String
dbConnection = dbConn()


When I run the debugger, I go to the default page. I type in my username and password (the main page is a login screen), and I recieve this error:

Cast from type 'OleDbConnection' to type 'String' is not valid.

Line 41:
Line 42: Dim strSQL As String
Line 43: Dim conn As New OleDb.OleDbConnection(dbConnection) Line 44: Dim cmd As New OleDb.OleDbCommand(strSQL, conn) Line 45: Dim reader As OleDb.OleDbDataReader

This is what is in my code right now:
Dim dbConnection As String
dbConnection = dbConn()

Dim strSQL As String
Dim conn As New OleDb.OleDbConnection(dbConnection)
Dim cmd As New OleDb.OleDbCommand(strSQL, conn)
Dim reader As OleDb.OleDbDataReader
Dim adapter As OleDb.OleDbDataAdapter


Any ideas??

Thanks

Reply With Quote
  #2  
Old April 15th, 2005, 12:25 AM
ZLA ZLA is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Saint Louis, MO
Posts: 13 ZLA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 46 m 37 sec
Reputation Power: 0
Your function returns a value of datatype System.Data.IDbConnection since it returns strConnection, not connectionString. When you call your function, you set a string variable to it:

Dim dbConnection As String
dbConnection = dbConn()

.Net doesn't know how to cast the IDbConnection value to a string.

I'm not sure I know what you're trying to do but I'm guessing you want to return a connection object to be used for database access. If so, you should call your function with something like the following:

Dim oConn as System.Data.IDbConnection = dbConn()

HTH.

Reply With Quote
  #3  
Old April 15th, 2005, 11:01 PM
zombie_man23 zombie_man23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 22 zombie_man23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 16 m
Reputation Power: 0
Cast from type 'OleDbConnection' to type 'String' is not valid.

Line 41: Dim conn As New System.Data.odbc.OdbcConnection(dbConn)
Line 42: Dim cmd As New System.Data.odbc.OdbcCommand
Line 43: Dim reader As System.Data.odbc.OdbcDataReader
Line 44: Dim adapter As System.Data.odbc.OdbcDataAdapter


Line 43 is where the error occurs.

Here is my dbConn function that I call. It may be something wrong with this.

Public Function dbConn()

Dim strConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Documents an" & _
"d Settings\EZ\Desktop\Alumni.mdb"

dbConn = strConnectionString

End Function

Thanks for the help!!!

Reply With Quote
  #4  
Old May 5th, 2005, 10:00 AM
ZLA ZLA is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Saint Louis, MO
Posts: 13 ZLA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 46 m 37 sec
Reputation Power: 0
An incorrect connection string shouldn't cause a cast error. I suspect dbConn may be defined in more than one place. Try replacing

Line 41: Dim conn As New System.Data.odbc.OdbcConnection(dbConn)

with

Line 41: Dim conn As New System.Data.odbc.OdbcConnection("Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Documents and Settings\EZ\Desktop\Alumni.mdb")

and see if you get the same error.

I'm not sure about the connection string itself (Ole DB Services=-4?). I use this site for reference: http://www.connectionstrings.com/. Click on Access and then the OLE DB connection.

HTH

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Calling MS Access Connection String problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT