Skip to content

Commit ed16b95

Browse files
authored
Merge pull request #100408 from joe-plumb/patch-1
Adding SQLite to Azure SQL migration tutorial
2 parents efc195d + 4602e56 commit ed16b95

File tree

8 files changed

+107
-0
lines changed

8 files changed

+107
-0
lines changed
42.3 KB
Loading
130 KB
Loading
137 KB
Loading
120 KB
Loading
Loading
257 KB
Loading

articles/sql-database/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@
530530
href: sql-database-security-tutorial.md
531531
- name: Stream data with Stream Analytics
532532
href: sql-database-stream-analytics.md
533+
- name: Migrate a SQLite database to Azure SQL Database Serverless
534+
href: tutorial-sqlite-db-to-azure-sql-serverless-offline.md
533535

534536
- name: Concepts
535537
items:
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: "Tutorial: How to migrate your SQLite database to Azure SQL Database Serverless"
3+
description: Learn to perform an offline migration from SQLite to Azure SQL Database Serverless by using Azure Data Factory.
4+
services: sql-database
5+
author: joplum
6+
ms.author: joplum
7+
manager: prda
8+
ms.service: sql-database
9+
ms.workload: data-services
10+
ms.topic: article
11+
ms.date: 01/08/2020
12+
---
13+
14+
# How to migrate your SQLite database to Azure SQL Database Serverless
15+
For many people, SQLite provides their first experience of databases and SQL programming. It's inclusion in many operating systems and popular applications makes SQLite one the most widely deployed and used database engines in the world. And because it is likely the first database engine many people use, it can often end up as a central part of projects or applications. In such cases where the project or application outgrows the initial SQLite implementation, developers may need to migrate their data to a reliable, centralized data store.
16+
17+
Azure SQL Database serverless is a compute tier for single databases that automatically scales compute based on workload demand, and bills for the amount of compute used per second. The serverless compute tier also automatically pauses databases during inactive periods when only storage is billed and automatically resumes databases when activity returns.
18+
19+
Once you have followed the below steps, your database will be migrated into Azure SQL Database Serverless, enabling you to make your database available to other users or applications in the cloud and only pay for what you use, with minimal application code changes.
20+
21+
## Prerequisites
22+
- An Azure Subscription
23+
- SQLite2 or SQLite3 database that you wish to migrate
24+
- A Windows environment
25+
- If you do not have a local Windows environment, you can use a Windows VM in Azure for the migration. Move and make your SQLite database file available on the VM using Azure Files and Storage Explorer.
26+
27+
## Steps
28+
29+
1. Provision a new Azure SQL Database in the Serverless compute tier.
30+
31+
![screenshot of Azure portal showing provisioning example for azure sql database serverless](./media/tutorial-sqlite-db-to-azure-sql-serverless-offline/provision-serverless.png)
32+
33+
2. Ensure you have your SQLite database file available in your Windows environment. Install a SQLite ODBC Driver if you do not already have one (there are many available in Open Source, for example, http://www.ch-werner.de/sqliteodbc/).
34+
35+
3. Create a System DSN for the database. Ensure you use the Data Source Administrator application that matches your system architecture (32-bit vs 64-bit). You can find which version you are running in your system settings.
36+
37+
- Open ODBC Data Source Administrator in your environment.
38+
- Click the system DSN tab and click "Add"
39+
- Select the SQLite ODBC connector you installed and give the connection a meaningful name, for example, sqlitemigrationsource
40+
- Set the database name to the .db file
41+
- Save and exit
42+
43+
4. Download and install the self-hosted integration runtime. The easiest way to do this is the Express install option, as detailed in the documentation. If you opt for a manual install, you will need to provide the application with an authentication key, which can be located in your Data Factory instance by:
44+
45+
- Starting up ADF (Author and Monitor from the service in the Azure portal)
46+
- Click the "Author" tab (Blue pencil) on the left
47+
- Click Connections (bottom left), then Integration runtimes
48+
- Add new Self-Hosted Integration Runtime, give it a name, select *Option 2*.
49+
50+
5. Create a new linked service for the source SQLite database in your Data Factory.
51+
52+
![screenshot showing empty linked services blade in Azure Data Factory](./media/tutorial-sqlite-db-to-azure-sql-serverless-offline/linked-services-create.png)
53+
54+
6. In Connections, under Linked Service, click New
55+
56+
7. Search for and select the "ODBC" connector
57+
58+
59+
![screenshot showing ODBC connector logo in the linked services blade in Azure Data Factory](./media/tutorial-sqlite-db-to-azure-sql-serverless-offline/linked-services-odbc.png)
60+
61+
8. Give the linked service a meaningful name, for example, "sqlite_odbc". Select your integration runtime from the "Connect via integration runtime" dropdown. Enter the below into the connection string, replacing the Initial Catalog variable with the filepath for the .db file, and the DSN with the name of the system DSN connection:
62+
63+
```
64+
Connection string: Provider=MSDASQL.1;Persist Security Info=False;Mode=ReadWrite;Initial Catalog=C:\sqlitemigrationsource.db;DSN=sqlitemigrationsource
65+
```
66+
67+
9. Set the authentication type to Anonymous
68+
69+
10. Test the connection
70+
71+
![screenshot showing successful connection in Azure Data Factory](./media/tutorial-sqlite-db-to-azure-sql-serverless-offline/linked-services-test-successful.png)
72+
73+
11. Create another linked service for your Serverless SQL target. Select the database using the linked service wizard, and provide the SQL authentication credentials.
74+
75+
![screenshot showing Azure SQL Database selected in Azure Data Factory](./media/tutorial-sqlite-db-to-azure-sql-serverless-offline/linked-services-create-target.png)
76+
77+
12. Extract the CREATE TABLE statements from your SQLite database. You can do this by executing the below Python script on your database file.
78+
79+
```
80+
#!/usr/bin/python
81+
import sqlite3
82+
conn = sqlite3.connect("sqlitemigrationsource.db")
83+
c = conn.cursor()
84+
85+
print("Starting extract job..")
86+
with open('CreateTables.sql', 'w') as f:
87+
for tabledetails in c.execute("SELECT * FROM sqlite_master WHERE type='table'"):
88+
print("Extracting CREATE statement for " + (str(tabledetails[1])))
89+
print(tabledetails)
90+
f.write(str(tabledetails[4].replace('\n','') + ';\n'))
91+
c.close()
92+
```
93+
94+
13. Create the landing tables in your Serverless SQL target environment by copying the CREATE table statements from the CreateTables.sql file and running the SQL statements in the Query Editor in the Azure portal.
95+
96+
14. Return to the home screen of your Data Factory and click "Copy Data" to run through the job creation wizard.
97+
98+
![screenshot showing the Copy Data wizard logo in Azure Data Factory](./media/tutorial-sqlite-db-to-azure-sql-serverless-offline/copy-data.png)
99+
100+
15. Select all tables from the source SQLite database using the check boxes, and map them to the target tables in Azure SQL. Once the job has run, you have successfully migrated your data from SQLite to Azure SQL!
101+
102+
## Next steps
103+
104+
- To get started, see [Quickstart: Create a single database in Azure SQL Database using the Azure portal](sql-database-single-database-get-started.md).
105+
- For resource limits, see [Serverless compute tier resource limits](sql-database-vCore-resource-limits-single-databases.md#general-purpose---serverless-compute---gen5).

0 commit comments

Comments
 (0)