About Me Projects Articles Experience Education Contact
Resume PDF Switch to Portuguese 🇧🇷
Back to Articles

The Ultimate Guide: How to Import Excel Data into SQL Server (Without Errors or Headaches)

Oct 30, 2025 5 min read SQL Server / Data Analytics
SQL and Data Concepts
Bridging the gap between Excel and SQL Server

How many times have you tried to import an Excel file into SQL Server and been greeted by a mysterious error message - "Access denied," "Incompatible driver," or the classic "Query failed"?

Those errors may look random, but they're not. In fact, SQL Server is just trying to protect itself, and most of these issues come down to a few simple configuration steps that are often overlooked.

In this article, you'll learn how to finally fix those headaches and turn Excel imports into a smooth, secure, and predictable process - using the power of T-SQL and the OPENROWSET function.

Tech Stack & Requirements

SQL Server Instance & Permissions
Microsoft Excel .xlsx / .csv Data Sources
T-SQL OPENROWSET Function
OLE DB Provider Access Database Engine

1. Why OPENROWSET Is Powerful (and a Bit Misunderstood)

OPENROWSET is a T-SQL function that lets you read external data - like Excel sheets, CSV files, or Access databases as if they were local SQL tables. Think of it as opening a temporary bridge between SQL Server and Excel.

But that bridge is locked by default. And that's where most people stumble: without proper configuration of the server, drivers, and permissions, SQL simply refuses to talk to Excel.

2. The Real Villains Behind the Errors

Before diving into solutions, meet the usual suspects:

3. The Step-by-Step Solution

Step 1 - Install the correct driver

Download and install Microsoft Access Database Engine 2016 (64-bit) if your SQL Server is 64-bit. (Check with SELECT @@VERSION;)

Step 2 - Enable Ad Hoc Distributed Queries

T-SQL
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;

EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;

Step 3 - Allow the driver to run "in-process"

T-SQL
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1;
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1;

Step 4 - Grant folder permissions

Make sure the SQL Server service account (e.g., NT SERVICE\MSSQLSERVER) has Read, Execute, and Modify permissions on the import folder.

Step 5 - Run the import

T-SQL
SELECT *
INTO dbo.ExcelProducts
FROM OPENROWSET (
    'Microsoft.ACE.OLEDB.12.0',
    'Excel 12.0;Database=C:\SQL_Imports\ImportToSQL.xlsx',
    'SELECT * FROM [ProductData$]'
);

4. Real-World Use Cases

In all these cases, OPENROWSET acts as a shortcut between Excel and SQL, saving time and avoiding manual imports.

5. Security: What Separates Pros from Amateurs

Leaving Ad Hoc Distributed Queries permanently enabled is a bad idea - it opens unnecessary risks on the server.

Here's the professional (and safe) workflow:

Pro Workflow
-- 1. Enable before import
EXEC sp_configure 'Ad Hoc Distributed Queries', 1; RECONFIGURE;

-- 2. Run your import here...

-- 3. Disable after use to secure the server
EXEC sp_configure 'Ad Hoc Distributed Queries', 0; RECONFIGURE;

Pro tip: For frequent or large-scale imports, use SSIS or Azure Data Factory - more secure, scalable, and automation-friendly.

6. Performance Tips & Best Practices

7. A Simple Analogy

Think of OPENROWSET as a temporary courier. It leaves SQL Server, visits Excel, picks up the data, and comes back.

But if the courier doesn't have the right key (driver), permission to enter (folder access), or the door open (server configuration), it's not going anywhere.

8. Final Thoughts: Master the Process, Boost Your Productivity

At first glance, OPENROWSET can look intimidating. But once configured properly, it becomes a powerful ally for anyone working with data.

Professionals who master this technique can:

Have you ever faced the infamous "Access denied" from SQL Server? How did you solve it?

Share your experience in the comments your story might save another professional's day!

And if you found this useful, save this post for the next time you need to connect Excel and SQL without breaking a sweat.

Enjoyed this insight?

Share knowledge with your network.

Have any questions or need consulting?

Get in Touch