Solved

Automate Excel upload to hosted SQL Server

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

831 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