Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

SQl 2005/Visual Basic 2008

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
megs28 - 24 Jul 2008 03:00 GMT
Please excuse my ignorance, as I'm not overly with the inner workings of SQL,
nor do I know programming very well.  I've been given the task of taking all
of the data from a table on our sql 2005 server, exporting it, and importing
it into a SQl 2005 express client.  This needs to be very straight forward,
and should not involve the management studio.

I've started a program in VB.net 2008 that exports the table into an XML
file.  I think I'm doing this part correctly, but cannot figure out how to
get the XML file into the remote database.  There is no replication, etc. for
me to be concerned with.  Below is a snipit of the export code, as well as
the import code that I'm stuck on.  I've left out the SQL connection
statement as I've got it down pat.  I'm also leaving the file extension off
for a reson, but it should be creating a .xml file during the export, not xsd.

From what I understand, I've read the XML file into the dataset properly, I
just need to figure out how to take the dataset and import it into the
database.  If anyone could offer some assitance or direction I would
appreciate it!!

EXPORT CODE
=====================
Private Sub Export()
       Dim sqlConn As New
System.Data.SqlClient.SqlConnection(StrConnection) 'OleDbConnection i
       Dim strFilename As String
       sqlConn.Open()
       ' Queries Database for _Product Table and writes to XML File
       Dim ds As New Data.DataSet()
       Dim da As New System.Data.SqlClient.SqlDataAdapter("select * from "
& strPricelist & "_Products", sqlConn)
       da.Fill(ds)
       strFilename = "C:\" & strPricelist & "_Products"
       ds.WriteXml(strFilename, Data.XmlWriteMode.WriteSchema)
       ' Queries Database for _Product Table and writes to XML File
       Dim ds2 As New Data.DataSet()
       Dim da2 As New System.Data.SqlClient.SqlDataAdapter("select * from "
& strPricelist & "_Folders", sqlConn)
       da2.Fill(ds2)
       strFilename = "C:\" & strPricelist & "_Folders"
       ds2.WriteXml(strFilename, Data.XmlWriteMode.WriteSchema)
       sqlConn.Close()
End Sub

=============
IMPORT CODE
================
Private Sub Import()
       Dim sqlConn As New
System.Data.SqlClient.SqlConnection(StrConnection) 'OleDbConnection i
       Dim strFilename As String
       Dim xdoc As XmlDataDocument = New XmlDataDocument()
       xdoc.DataSet.ReadXmlSchema(textReader)
       sqlConn.Close()
End Sub
William Vaughn (MVP) - 25 Jul 2008 19:09 GMT
Ah, no. This can be done any number of ways but you have chosen one of the
most code-intensive, least secure and slowest methods (IMHO).
Consider that SSIS (SQL Server Integration Services) can handle this as can
the bulk copy command-line utility (BCP) or better yet, the TSQL bulk copy
function or the SqlBulkCopy API. SSIS scripts can be written and executed on
demand as can BCP jobs. The SqlBulkCopy API uses a high-speed technique to
move data (even lots of data) from server instance to instance with very
little trouble. Another approach you might consider is the new ADO.NET 3.5
sync services which can synchronize two (or more) database tables.

I discuss most of these (but not Sync Services) in my book.
Signature

__________________________________________________________________________
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)
____________________________________________________________________________________________

> Please excuse my ignorance, as I'm not overly with the inner workings of
> SQL,
[quoted text clipped - 59 lines]
>        sqlConn.Close()
> End Sub
megs28 - 29 Jul 2008 19:38 GMT
Thanks for the suggestions, William.

I should have clarified, but my SQL express clients are all around the world
and are not connected via VPN.  They have no connection whatsoever to the
master installation.  The software I'm using (Quotewerks) has a built in sync
tool, but it requires SMB traffic.  For some ridiculous reason, management
thinks that a manual import/export of the pricelists is a better option than
providing people with VPN access.  Talking sense into them is like talking to
a brick wall.

With that in mind, I don't think SSIS or BCP will do the job, right?  I will
have to look into the SQLbulkcopy more (was going to write this into the vb
program), and go from there.

> Ah, no. This can be done any number of ways but you have chosen one of the
> most code-intensive, least secure and slowest methods (IMHO).
[quoted text clipped - 70 lines]
> >        sqlConn.Close()
> > End Sub
William Vaughn (MVP) - 29 Jul 2008 19:42 GMT
You're right. SSIS/BCP/SQLBulkCopy all assume (at least) VPN  connections.
Since you're using what we used to call "sneaker net" (where you physically
pass around a file), I might consider using an easily transported DBMS file
like SQLCe. Its tight, secure, fast and does not require a lot of overhead.
One approach would be to pass the file and use the VB program to suck in the
data (via SqlBulkCopy) to the local SQL Server database.

Signature

__________________________________________________________________________
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)
____________________________________________________________________________________________

> Thanks for the suggestions, William.
>
[quoted text clipped - 106 lines]
>> >        sqlConn.Close()
>> > End Sub
 
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



©2009 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.