Solved

Automate Excel upload to hosted SQL Server

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

932 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

11 Experts available now in Live!

Get 1:1 Help Now