Solved

Automate Excel upload to hosted SQL Server

Posted on 2014-10-23
1
115 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
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now