473,382 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Can I change a connection string of the object data source programmatically ?

Hello .

Please find below my questions - I hope some of the ASP.NET experts of
this forum will answer to those beginner's questions :

My Web site should be able to work with either SQL Server or Access
database as following :

It will connect first to the Master database (SQL or Access,
connection String of this database should be read from the C:\WINDOWS
\XXX.INI file).
It will have one or more sub-databases ( SQL Or Access , list of sub-
databases is saved in one of the Master tables .)
The schema of all sub-databases is the same , no matter if this is
Access or SQL .

My site should present sub-databases drop-down list ( which will be
retrieved from the Master database ) and then will connect to
specified sub-database ( either Access or SQL ) and will display data
from this database .
I would like to be able to switch database type ( database provider )
programmatically on the data source level so it is transparent for the
application code .
Can I do it ?
Can I change a connection string of the object data source
programmatically ? If so , how can I do so ?
Can I then call the same methods which will call Access or SQL
database as needed ?
Or . should I create different table adapters , specify SQL connection
string for one of them , OLEDB connection string to another ,
duplicate all methods and have a if/else block each time I call a
methods of those adapters ?
If so , would it be easier then NOT to use data objects and use just
different providers ?
Do I miss something here ?

Thanks in advance for your help ,
Orit Chanukov .

Jun 19 '07 #1
2 3244
I think that you will have to use different DataAdapters with the If
statement like you mentioned. Because SQL Server and Access use different
DataAdapters, Connections, and other objects for accessing databases, you
would end up writing the code for each of them separately anyway. The
connection string can be changed programmatically using the ConnectionString
property of the connection (this property is inherited from the
System.Data.Common.DbConnection class, so all the connection types have it)
One thing that may come in useful at some point in your code (or maybe not,
I haven't seen your code and algorithms) is using the parent classes, such
as System.Data.Common.DbConnection, and assign the appropriate connection
type to it. This could help you organize your variables in some situations,
you decide what your preference is. The reason there is not an easier way to
do this is because applications are not expected to use multiple database
providers in the same application. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Orit" <or******@gmail.comwrote in message
news:11*********************@x35g2000prf.googlegro ups.com...
Hello .

Please find below my questions - I hope some of the ASP.NET experts of
this forum will answer to those beginner's questions :

My Web site should be able to work with either SQL Server or Access
database as following :

It will connect first to the Master database (SQL or Access,
connection String of this database should be read from the C:\WINDOWS
\XXX.INI file).
It will have one or more sub-databases ( SQL Or Access , list of sub-
databases is saved in one of the Master tables .)
The schema of all sub-databases is the same , no matter if this is
Access or SQL .

My site should present sub-databases drop-down list ( which will be
retrieved from the Master database ) and then will connect to
specified sub-database ( either Access or SQL ) and will display data
from this database .
I would like to be able to switch database type ( database provider )
programmatically on the data source level so it is transparent for the
application code .
Can I do it ?
Can I change a connection string of the object data source
programmatically ? If so , how can I do so ?
Can I then call the same methods which will call Access or SQL
database as needed ?
Or . should I create different table adapters , specify SQL connection
string for one of them , OLEDB connection string to another ,
duplicate all methods and have a if/else block each time I call a
methods of those adapters ?
If so , would it be easier then NOT to use data objects and use just
different providers ?
Do I miss something here ?

Thanks in advance for your help ,
Orit Chanukov .

Jun 19 '07 #2
On Jun 18, 9:55 pm, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
I think that you will have to use different DataAdapters with the If
statement like you mentioned. Because SQL Server and Access use different
DataAdapters, Connections, and other objects for accessing databases, you
would end up writing the code for each of them separately anyway. The
connection string can be changed programmatically using the ConnectionString
property of the connection (this property is inherited from the
System.Data.Common.DbConnection class, so all the connection types have it)
One thing that may come in useful at some point in your code (or maybe not,
I haven't seen your code and algorithms) is using the parent classes, such
as System.Data.Common.DbConnection, and assign the appropriate connection
type to it. This could help you organize your variables in some situations,
you decide what your preference is. The reason there is not an easier way to
do this is because applications are not expected to use multiple database
providers in the same application. Good Luck!
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

"Orit" <oritc...@gmail.comwrote in message

news:11*********************@x35g2000prf.googlegro ups.com...
Hello .
Please find below my questions - I hope some of the ASP.NET experts of
this forum will answer to those beginner's questions :
My Web site should be able to work with either SQL Server or Access
database as following :
It will connect first to the Master database (SQL or Access,
connection String of this database should be read from the C:\WINDOWS
\XXX.INI file).
It will have one or more sub-databases ( SQL Or Access , list of sub-
databases is saved in one of the Master tables .)
The schema of all sub-databases is the same , no matter if this is
Access or SQL .
My site should present sub-databases drop-down list ( which will be
retrieved from the Master database ) and then will connect to
specified sub-database ( either Access or SQL ) and will display data
from this database .
I would like to be able to switch database type ( database provider )
programmatically on the data source level so it is transparent for the
application code .
Can I do it ?
Can I change a connection string of the object data source
programmatically ? If so , how can I do so ?
Can I then call the same methods which will call Access or SQL
database as needed ?
Or . should I create different table adapters , specify SQL connection
string for one of them , OLEDB connection string to another ,
duplicate all methods and have a if/else block each time I call a
methods of those adapters ?
If so , would it be easier then NOT to use data objects and use just
different providers ?
Do I miss something here ?
Thanks in advance for your help ,
Orit Chanukov .- Hide quoted text -

- Show quoted text -
Thanks a lot , Nathan .
That what I thought .
Orit,

Jun 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Moore | last post by:
does anyone have an example of how to get the connection string object converted to a string variable type in order for me to call a function?
1
by: Siva | last post by:
Hi, I have a 3 tier ASP.Net app for a handheld which needs to fetch orders from database via a DAL and populate it in a gridview using objectdatasource. In the search page I have a few parameters...
1
by: Ram | last post by:
Hi All, I am using Object Data Source to bind data in the gridview. I have set the property AllowSorting=true. While running the application, I could sort the data only in ascending order. Is...
0
by: Annie | last post by:
Hello guys, We are planning for a big project ... and in the warming up stages ... we are trying to develop the applicaiton in n-tier. One of the option is to use the ASP.net object...
1
by: Orit | last post by:
Hello . Please find below my questions - I hope some of the ASP.NET experts of this forum will answer to those beginner's questions : My Web site should be able to work with either SQL Server...
2
by: =?Utf-8?B?RGF2ZSBU?= | last post by:
I have a list box that is bound to an object data source. I added a column, say ColumnC, to my typed data set and for it's expression I entered ColumnA + ': ' + ColumnB When I preview the...
3
by: Fresno Bob | last post by:
When you bind to the object data source you can bind to the underlying dataset that is returned by the select statement but can you bind to the properties of the object? MSDN says the...
0
by: =?Utf-8?B?Sm9l?= | last post by:
I have a user control that is in a FormView using an ObjectDataSource. When the page renders the form correctly displays the data from the data source. When I then change data and hit update, my...
6
by: little83 | last post by:
Dear all i wrote one class to deal with sql database to insert and read data from that class only...and based on that one of the parmeters or the class is the sqlconnection SqlConnection...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.