Replacing tables in SQL EXPRESS

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Can someone please set me on the way on how to replace certain tables in a
(new) SQL EXPRESS database file by tables of the same name in another
(target) SQL EXPRESS database file?
I would like to do this through code in VB.NET 2005. I presume I have to
use ADO.NET 2.0 code.
Is it correct I first have to delete the original table in the target
database by a DROP statement and the copy the new table into the target
database? Or do I use a DELETE statement and the fill the empty database by
the new data?
Do I need a second connection to the database with the new tables?
I am a newbie in this matter, so any help would greatly be appreciated.
Also lins to usefull example code is welcome.
I searched already for info on the internet, but mostly the information I
found is not very usefull for my purpose.

Many thanks and greetings from Brugge (Bruges - Belgium),

Michel
 
Michel,
Check out the SqlBulkCopy method in ADO.NET 2.0. It can copy an entire
table in a single (high-speed) operation. I have an example of its use in my
book.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 
Hello,

Thank you very much for your reply.
If I understand correctly SqlBulkCopy can only add rows from one table to
another. What I want is just replace one table by another (perhaps delete
the table to be replaced first).
When I delete the rows of the table, I get an error that I want to import
duplicate values (e.g. the key values of the table). When I delete the
entire table first, SqlBulkCopy gives an error that th destination table is
not found.

How can I fix that?

Many thanks and greetings from Brugge (Bruges - Belgium),

Michel
 
Dear Mr. Vaughn,

I bought your extensive book and the only reference to the SqlBulkCopy
method I find in the index refers to pages 527 - 528.
There is a small chapter on the matter, but I do not find any examples or
code to demonstrate its use.

On the DVD are some examples but none refer to the SqlBulkCopy method, as
far as I could see.

As I am new to all matters regarding SQL Server, can you please point me in
the direction where I can find sample code and further information on how to
achieve the tasks I described earlier?

Many thanks and greetings from Brugge (Bruges - Belgium),

Michel
 
If you can wait 48 hours, I'll write up a supplemental whitepaper and post
it to the book's premium area.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
 
I have posted an updated example on the Hitchhiker's Guide support site. As
a registered user you should have full access to the project.
Let me know if you have other issues. I'll be writing a more in-depth
discussion of the method (to supplement what's already in the book) and post
that in the next couple of days. I also expect to publish this whitepaper
and part of the code in my regular "First Tuesday" Developer.Com article.
Note that the example posted to the readers' side also includes the source
code for my SqlCmd class that's designed to parse a text file containing an
SQL script and execute it against a selected SqlConnection. This will appear
in a future Developer.Com article published at a later date.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
 
Dear Mr. Vaughn,

Thank you very much for your help.
I tried the whole day to access the Hitchhiker's Guide support site.
Unfortunately, I only got a "HTTP error 550" or a "Server Error in '/'
Application" with the following comment:

Runtime Error
Description: An application error occurred on the server. The current custom
error settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could, however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable
on remote machines, please create a <customErrors> tag within a "web.config"
configuration file located in the root directory of the current web
application. This <customErrors> tag should then have its "mode" attribute
set to "Off".


<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirect" attribute of the application's
<customErrors> configuration tag to point to a custom error page URL.


<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>

I use Microsoft Internet Explorer 7.0.5730.11.

I wll have to wait until these matters are fixed.

Many thanks and greetings from Brugge (Bruges - Belgium),

Michel
 
Yup, it seems to be down. I'll check it out.
Thanks for letting me know.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
 
Okay, it should be working now (at least it's working here).
Please email me directly if you have another issue.
Thanks again.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
 
Back
Top