Hi there,
I'm trying to use MSAccess as a "container" to move data around from
one MS-SQL server DB to another. This is basically already a design
decision that has been made for a lot of reasons and can't be changed
by me.
What I was wondering is what is the bet way to populate the MS-Access
DB. The DB will only contain 6 tables which will have a very small
amount of data in them. I have tried to use ADO.Net to read the data
from MS-SQL into a DataTable and then save it into the MS-Access DB
using again using a DataTable populated from the first, but I can't
seem to get the syntax right.
Even after I execute the Update method nothing happens to the Access
DB. So I modified one of the values in the data rows ('myRow("name") =
"hi there") and this seemed to force an update, but then threw a
concurrency error.
Attached below is the code I was using, can anyone help?
JPO
Dim cnnA As System.Data.OLE db.OleDbConnect ion = New
System.Data.OLE db.OleDbConnect ion(QuantumConn ection)
Dim cnnAccessDB As System.Data.OLE db.OleDbConnect ion = New
System.Data.OLE db.OleDbConnect ion(AccessDB)
cnnA.Open()
cnnAccessDB.Ope n()
Dim daDataAdapterA As New
System.Data.Ole Db.OleDbDataAda pter("SELECT * FROM Advmast", cnnA),
dtDataTableA As New DataTable
Dim daAccessDB As New
System.Data.Ole Db.OleDbDataAda pter("SELECT * FROM Advmast",
cnnAccessDB), dtAccessDB As New DataTable
Dim myRow As DataRow
Dim i As Int16
daDataAdapterA. Fill(dtDataTabl eA)
dtAccessDB = dtDataTableA.Cl one
dtAccessDB.Begi nLoadData()
For Each myRow In dtDataTableA.Ro ws
'myRow("name") = "hi there"
dtAccessDB.Impo rtRow(myRow)
daAccessDB.Upda te(dtAccessDB)
Next myRow
dtAccessDB.EndL oadData()
daAccessDB.Upda te(dtAccessDB)
dtAccessDB.Acce ptChanges()
cnnAccessDB.Clo se()
cnnA.Close()
cnnAccessDB = Nothing
cnnA = Nothing 4 1629
Is there a reason you don't just create a DTS package and point it to
an empty .mdb database file? Then, run the package from your code?
Here is a VBScript that does this sort of thing. You could use COM
interop to utilize much of it in .NET. http://www.eggheadcafe.com/articles/20030923.asp
--
2005 Microsoft MVP C#
Robbe Morris http://www.robbemorris.com http://www.masterado.net/home/listings.aspx
"JPO" <ju************ *****@sungard.c om> wrote in message
news:a3******** *************** ***@posting.goo gle.com... Hi there,
I'm trying to use MSAccess as a "container" to move data around from one MS-SQL server DB to another. This is basically already a design decision that has been made for a lot of reasons and can't be changed by me.
What I was wondering is what is the bet way to populate the MS-Access DB. The DB will only contain 6 tables which will have a very small amount of data in them. I have tried to use ADO.Net to read the data from MS-SQL into a DataTable and then save it into the MS-Access DB using again using a DataTable populated from the first, but I can't seem to get the syntax right.
Even after I execute the Update method nothing happens to the Access DB. So I modified one of the values in the data rows ('myRow("name") = "hi there") and this seemed to force an update, but then threw a concurrency error.
Attached below is the code I was using, can anyone help?
JPO
Dim cnnA As System.Data.OLE db.OleDbConnect ion = New System.Data.OLE db.OleDbConnect ion(QuantumConn ection) Dim cnnAccessDB As System.Data.OLE db.OleDbConnect ion = New System.Data.OLE db.OleDbConnect ion(AccessDB)
cnnA.Open() cnnAccessDB.Ope n()
Dim daDataAdapterA As New System.Data.Ole Db.OleDbDataAda pter("SELECT * FROM Advmast", cnnA), dtDataTableA As New DataTable Dim daAccessDB As New System.Data.Ole Db.OleDbDataAda pter("SELECT * FROM Advmast", cnnAccessDB), dtAccessDB As New DataTable
Dim myRow As DataRow Dim i As Int16
daDataAdapterA. Fill(dtDataTabl eA)
dtAccessDB = dtDataTableA.Cl one dtAccessDB.Begi nLoadData() For Each myRow In dtDataTableA.Ro ws 'myRow("name") = "hi there" dtAccessDB.Impo rtRow(myRow) daAccessDB.Upda te(dtAccessDB) Next myRow dtAccessDB.EndL oadData()
daAccessDB.Upda te(dtAccessDB) dtAccessDB.Acce ptChanges()
cnnAccessDB.Clo se() cnnA.Close() cnnAccessDB = Nothing cnnA = Nothing
JPO,
Beside the question from Robbie.
The problem with this program is probably that during the fill the
acceptchanges is done and there will be no update.
To prevent that you can use the acceptchangesdu ringfill = false http://msdn.microsoft.com/library/de...gfilltopic.asp
When you cannot do as Robbie wrote than the next good step can be doing it
streaming by reading using the datareader and inserting using the
execute.nonquer y
There is in my opinion no need to use two datatables.
I hope this helps,
Cor
Why dont you just use DTS and go straight from one MSSQL server to another ?
On 31 Mar 2005 17:51:09 -0800, ju************* ****@sungard.co m (JPO) wrote:
¤ Hi there,
¤
¤ I'm trying to use MSAccess as a "container" to move data around from
¤ one MS-SQL server DB to another. This is basically already a design
¤ decision that has been made for a lot of reasons and can't be changed
¤ by me.
¤
You can probably do this directly without using a DataSet:
Function ImportSQLServer ToAccess() As Boolean
Dim AccessConn As New System.Data.Ole Db.OleDbConnect ion("Provider=M icrosoft.Jet.OL EDB.4.0;"
& _
"Data Source=e:\My Documents\db1.m db")
AccessConn.Open ()
Dim AccessCommand As New System.Data.Ole Db.OleDbCommand ("SELECT * INTO Orders FROM [Orders]
IN '' [ODBC;Driver={SQ L Server};Server= (local);Databas e=Northwind;Tru sted_Connection =yes];",
AccessConn)
AccessCommand.E xecuteNonQuery( )
AccessConn.Clos e()
End Function
Paul
~~~~
Microsoft MVP (Visual Basic) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Caroline |
last post by:
I need to update a table by copying a column from another table
(having the same
structure, but on another database), from the record having the same
primary key.
1 - What is the correct query?
2 - I tried copying them record by record, but the datatype is ntext,
(it displays <long
|
by: Matteo Settenvini |
last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using
g++ 3.3.x.
I had been taught that an array isn't a lot different from a pointer
(in fact you can use the pointer arithmetics to "browse" it). So I
expected that when I run this program, I get both c1.A and c2.A
pointing to the same address, and changing c1.A means that also...
|
by: 21novembre |
last post by:
Hi all,
I made a question several days before to describe my strange trouble of
mysqldump. But I still can't figour it out. Well, I just want to ask
another question whether I could just backup my databases by copying
the data folder to some place? Then if I meet some disaster, could I
just copy the backup folder back to recover my...
|
by: Jani Tamminen |
last post by:
I want to copy data from our production database to the development
database. I want to move only the data. I do not need the table structure,
constrains or anything else.
I think I can use the db2move command to export out all the data like the
following:
db2move dbname export -tc schema1
|
by: Nathan Sokalski |
last post by:
I am writing an ASP.NET application in which I need to copy DataRows from
one DataTable to another. When I use code such as the following:
temprows = nodes.Select("state='PA'")
temptable.Clear()
For Each row As DataRow In temprows
temptable.Rows.Add(row)
Next
| |
by: |
last post by:
Hello,
I have a program that starts a new thread to backup files
from a computer over the network to our server. The
problem is when it is copying the files you can hardly
navigate around in windows explorer. I would like this
program to backup users files somewhat transparently. As
it is now they can hardly navigate through their files...
|
by: Mike9900 |
last post by:
What is the best way to copy DataRow from one table to another table,
without copying its structure, which means copying only its data.
--
Mike
|
by: Mr John FO Evans |
last post by:
Am looking at adding structures to an embedded C emulator but am wondering
what the standard is for copying structures(ie structa=structb) which
contain pointers to memory and which are therefore not contiguous in memory.
When such structures are copied what should C do with these elements? Or
should copying be illegal in this case?
John
|
by: mike3 |
last post by:
Hi.
I have an interesting problem. The C program presented below takes
around
12 seconds to copy 128 MB of data on my machine. Yet I know the
machine can go
faster since a copying done at a DOS prompt takes only 4 seconds to do
the same
128 MB copy (and a copy is both a read and write.). So why is this
thing like 3x
|
by: Tom |
last post by:
I am trying to update another developers code, and am stuck in a
cludge.
It works like this:
A user uploads a file from the web page. Our code reads from a
NetworkStream to a Filestream, and writes out a temporary file. Then
the file is parsed (The file contains HTML data + the actual binary
file that was transmitted). As part of the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |