0

I have an MS Access database table that I exported to SQL Server 2012 without the data. So now I'd like to copy the data from the access table to the sql table line by line.

    Dim conn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(Configuration.ConfigurationManager.ConnectionStrings("ACCESS_DB_DataConnectionString").ToString())
    Dim comm As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand("Select * FROM " + accessTable)
    Dim rdr As System.Data.OleDb.OleDbDataReader

    Try
        conn.Open()
        rdr = comm.ExecuteReader

        While rdr.Read
             InsertRecord()
        End While
        rdr.Close()
    Catch ex As Exception
        'Error
    Finally
        comm.Dispose()
        conn.Close()
        conn.Dispose()
    End Try
End Sub

Private Sub InsertRecord()
    'What do I do here?  Select into?  But how?
End Sub

I don't want to use a regular insert because I don't care to type out all of the column names. The end goal is to copy what records I can and skip over and obtain the IDs of all the rows that error out.

Thank you

5
  • The biggest issue you will have when working with databases is forcing yourself to think about data movements as line by line. Mar 27, 2015 at 17:16
  • What is so hard about getting the column names? And you can have Linked Server to Access from SSMS.
    – paparazzo
    Mar 27, 2015 at 17:45
  • To be honest, its a terrible set of tables (not just one) with a gazillion columns. I don't want to do it for every table. Mar 27, 2015 at 18:21
  • Really a gazillion columns and you tried import with failures and you think the question as stated is the solution? -1
    – paparazzo
    Mar 27, 2015 at 18:29
  • eh. its ok if you don't know. Adam gave a helpful answer. Mar 27, 2015 at 18:33

1 Answer 1

2

Please take a look at the "SQL Server Import and Export Data" program that comes with SQL Server Management Studio. It does a spectacular job of transferring data to/from SQL Server and a variety of other formats like Access, Excel, OLE, and many others.

SQL Server Import and Export Data

2
  • Originally, I did use the import/export data program from SQLServer; however, it would error out part way through the data copy with different errors and give no detail as to where. Most of the time. Sometimes I was able to track down null values where they were not supposed to be but for the most part, I was getting barely a 1/3 of the data before getting shut down. I even tried using the ignore on error option, but it never ignored them. Mar 27, 2015 at 18:20
  • Thanks Adam, I actually kept running it after it error'd out and found that each time it got further. I appreciate the help. Mar 27, 2015 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.