Solved

Automate Excel upload to hosted SQL Server

Posted on 2014-10-23
1
122 Views
Last Modified: 2014-10-24
We have a database running on a hosted server which consist of 3 tables -table1, table2, and table3. Data is locally collected using using Excel. So each worksheet corresponds to each table in the SQL database and the columns to the fields in the database tables (table1, table2, and table3).

Currently I am manually activating task, import data, choose a datasource etc... to import the Excel data onto the hosted server.

Since I am running SQL Server Express to access the hosted database, I do not have the SSIS option. In addition, the hosted server does not allow openrowset.

 What is the best way to automate the import process from the Excel worksheets to the tables on the hosted database ?
0
Comment
Question by:Errol Farro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
slubek earned 500 total points
ID: 40401118
I had similar problem, but data from Excel had to be inserted into different tables.
So I created sp_insert_data procedure in SQL Server, and executed it from VBA for every row like this:

Sub SQL_Open()
    ConnString = "DRIVER={SQL Server};SERVER=MYDATABASESERVER;UID=;PWD=;Database=DATABASE"
    Set cn = New ADODB.Connection
    cn.Open ConnString
End Sub

Sub SQL_Close()
    cn.Close
End Sub

Sub SQL_execute(sqlstring As String)
    Dim err As ADODB.Error

    cn.Execute (sqlstring)
    For Each err In cn.Errors
        SQL_Error (err.Description)
        Error = True
    Next
End Sub

Sub SQL_Error(s As String)
    Cells(Row, 1).Select
    MsgBox s
End Sub

Public Sub SQL_Import()
    Error = False
    Row = 2
    Col = 1
    
    SQL_Open
    
    While (Cells(Row, Col).Value <> "") And (Not Error)
        SQL_Insert (Row)
        Row = Row + 1
    Wend

    SQL_Close
End Sub

Private Sub SQL_Insert(R As Integer)
  Sql = "exec sp_insert_data  "
  Sql = Sql & Cells(R, 2).Value & ", "
  Sql = Sql & Cells(R, 3).Value & ", "
...
  SQL_execute (Sql)
End Sub

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question