473,503 Members | 4,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Casting oledb to Sqlclient objects

2 New Member
Dear Experts,

I have a situation , I am sure about the best approach for it. I have a database application that is designed to handle both SQLServer database and Oleddb "Access mdb" database. the issue is that during application start up , the application detects the configuration file and decides which database to use , eg , oledb to Sqlclient objects. the problem is that the application itself is, eg code to use teh sqlclient objects at different locations of the program. If i need to use oledb , i need to replace all of the sqlclient objects with oledb. who can i do it at run time. the bad solution will be to make at make both objects and decide which one to use , but the application is large. so it will be un-logic to use this approach. I tried to define an object as below

Expand|Select|Wrap|Line Numbers
  1.     Public aa As SqlClient.SqlConnection
  2.     Public bb As OleDb.OleDbConnection
  3.     Public gg as object
  4.  
  5.    if applicType="AccessDatabase" then directcast(gg,oledib.oleDbConnection") 

but this gave me an error .

I tried also :

Expand|Select|Wrap|Line Numbers
  1.    if applicType="AccessDatabase" then directcast(aa,oledib.oleDbConnection")
  2.  
but gave an error that I can not cast sqlclient to oledb .


Any solution ?

Thanks,
Sep 29 '12 #1
2 3047
ZiadElmalki
43 New Member
That is not possible because neither the OleDbConnection or SqlConnection derive from each other. In the System.Data namespace there are some basic classes and interface for ADO.NET. For connection could use IDbConnection interface as abstraction
Oct 25 '12 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Both the OleDBConnection class and the SqlConnection class inherit from the Common.DBConnection class.

So, in theory, you can declare your connection as a DbConnection and instantiate it as either a OleDbConnection or a SqlConnection later.

That way, when you're doing your direct cast, it will work properly.

-Frinny
Oct 25 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1977
by: Frank Rizzo | last post by:
I have an app that has to connect to various data sources (ms sql server, sybase, etc...). For this reason I have OdbcConnection, OleDb Connection and SqlClient objects. When an error happens, I...
2
1571
by: Bernardo | last post by:
Hi, Anyone knows what are the best database objects? The COM ADO is better then Data.OleDb or Data.SqlClient? Thanks,
0
2547
by: Yangtsi River | last post by:
Hi, I am using Access to practice database application developing, thus the namespace system.data.oledb is used instead of system.data.sqlclient, which is used for SQL server. So the classes I...
4
3646
by: Robert Hanson | last post by:
Hi All, I am trying to add a record to a datatable that is connected to an Access database. I had no trouble with string and date fields, but for this record, I have two Long Integer field...
0
302
by: Brian Hanson | last post by:
Hi, I have an unusual problem that just showed its ugly head at a pretty bad time. I have an asp.net (VB) app that takes data from an Excel sheet and puts it into SQL Server. I get the data...
2
1570
by: Lasse Edsvik | last post by:
Hello I was wondering if you guys could help me out...... I might have mixed the things up so bare with me. I was wondering if I should use datatable or dataset when displaying data in my...
13
1894
by: Ron L | last post by:
I am working on an application that is a front-end for a SQL database. While it is not an immediate requirement, the application will probably be required to be able to connect via the internet at...
5
1655
by: mrmagoo | last post by:
I'm using the System.Data.OleDb for SQL Server access, and it works perfectly. However, I see a lot of code examples that use System.Data.SqlClient. So I try it and it and can't get it to work. ...
0
1086
by: Sylvain Devidal | last post by:
Hello, I'm designing a web application that must be able to connect different databases. So I decided to use OleDb connector instead of SqlClient. While with SqlClient, I can run queries like...
3
1413
by: =?Utf-8?B?TWlrZVM=?= | last post by:
Below is the code for 2 separate functions. The first one gets data from an Access database and works fine. The second one is almost a duplicate except it gets data from an SQL database. It...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7313
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7441
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.