Changing connection string of a strong typed dataset

A

Ammar S. Mitoori

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 ?
 
C

Colbert Zhou [MSFT]

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 address removed).
 
G

Gregory A. Beamer

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! |
*******************************************
 
W

William Vaughn \(MVP\)

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
____________________________________________________________________________________________
 
M

Miha Markic

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top