Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Orit - 19 Jun 2007 01:05 GMT
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 .
Nathan Sokalski - 19 Jun 2007 05:55 GMT
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!
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

> Hello .
>
[quoted text clipped - 35 lines]
> Thanks in advance for your help ,
> Orit Chanukov .
Orit - 20 Jun 2007 03:20 GMT
> I think that you will have to use different DataAdapters with the If
> statement like you mentioned. Because SQL Server and Access use different
[quoted text clipped - 55 lines]
>
> - Show quoted text -

Thanks a lot , Nathan .
That what I thought .
Orit,

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.