PC Review


Reply
Thread Tools Rate Thread

Changing connection string of a strong typed dataset

 
 
Ammar S. Mitoori
Guest
Posts: n/a
 
      26th Aug 2009

if at design time i created a dataset and tableadapters with wizard and
connected them to the database through a connection string saved in the
app.config file, and then at run time i changed the connection string to
another database with different name but its tables have same name of the
old one with everything will work fine ? all the tableadapters fill and
update commands ?
 
Reply With Quote
 
 
 
 
Colbert Zhou [MSFT]
Guest
Posts: n/a
 
      26th Aug 2009
Hello,

Thanks for using Microsoft Newsgroup Support Service, my name is Colbert
Zhou [MSFT] and I will be working on this issue with you.

The connection string determines which database to query, and the
TableAdapter, SelectCommand, UpdateCommand, DeleteCommand determinds what
and how to query the specified database. They do not depend each other.
That is to say, as long as you new target database has the same table as
the orignal one. It should work!

Please note when I say "same table", I mean not only the name of the table
should remain same, the schema should also be same as the original
ones.(name, column count, column names, column type, relationship)

Actually, I have a quick test and it works fine in my side when I
dynamically change config file's connection string to target another
database.

Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      26th Aug 2009
=?Utf-8?B?QW1tYXIgUy4gTWl0b29yaQ==?= <(E-Mail Removed)> wrote in
news:4646BDAE-5EF6-4BE2-B376-(E-Mail Removed):

>
> if at design time i created a dataset and tableadapters with wizard
> and connected them to the database through a connection string saved
> in the app.config file, and then at run time i changed the connection
> string to another database with different name but its tables have
> same name of the old one with everything will work fine ? all the
> tableadapters fill and update commands ?
>



if you set it up at design time and the main difference, at runtime, is
the name of the database (ie, the schema is the same - ie, the table
name and all column names and data types are the same), you should not
have a problem. Just change the connection string and roll.

If you mean something beyond this, I am lost.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
William Vaughn \(MVP\)
Guest
Posts: n/a
 
      27th Aug 2009
I don't change the Connection string. I point to an aliased Data Source
instead. This way, when I want to direct the query to another database, it's
simply a matter of changing the alias. Once changed, all applications that
address the alias are redirected to the new data source--without recompile
or redeployment.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
http://betav.com http://betav.com/blog/billva
____________________________________________________________________________________________



"Ammar S. Mitoori" <(E-Mail Removed)> wrote in message
news:4646BDAE-5EF6-4BE2-B376-(E-Mail Removed)...
>
> if at design time i created a dataset and tableadapters with wizard and
> connected them to the database through a connection string saved in the
> app.config file, and then at run time i changed the connection string to
> another database with different name but its tables have same name of the
> old one with everything will work fine ? all the tableadapters fill and
> update commands ?


 
Reply With Quote
 
Miha Markic
Guest
Posts: n/a
 
      29th Aug 2009
Besides Bill's option which is the best approach, there is an easier,
hackier one:
You can try assigning your connection instance to each adapter
(xxxtableadapter.Connection) before doing any database operation as well.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: blog.rthand.com

"Ammar S. Mitoori" <(E-Mail Removed)> wrote in message
news:4646BDAE-5EF6-4BE2-B376-(E-Mail Removed)...
>
> if at design time i created a dataset and tableadapters with wizard and
> connected them to the database through a connection string saved in the
> app.config file, and then at run time i changed the connection string to
> another database with different name but its tables have same name of the
> old one with everything will work fine ? all the tableadapters fill and
> update commands ?


 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BLL with Typed DataSet & Application Setting for Connection String =?Utf-8?B?Z2VvZ3J1dmVu?= Microsoft ASP .NET 1 9th Oct 2007 02:20 AM
Re: Changing the "Connection String" for a "Strongly Typed DataSet" Dave Sexton Microsoft C# .NET 1 13th Dec 2006 02:08 PM
Re: Changing the "Connection String" for a "Strongly Typed DataSet" Sheng Jiang[MVP] Microsoft C# .NET 0 13th Dec 2006 01:30 PM
web.config connection string for typed dataset in different assemb =?Utf-8?B?VGVuRG90?= Microsoft ASP .NET 1 15th May 2006 08:13 PM
Set connection string at run time for typed DataSet (Framework 2.0 =?Utf-8?B?VGhvbWFzIFRheWxvcg==?= Microsoft ADO .NET 6 20th Jan 2006 04:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:19 PM.