?
Solved

Automate Excel upload to hosted SQL Server

Posted on 2014-10-23
1
Medium Priority
?
125 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

764 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