mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Moving to Features and readding the Readme.md
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
IF EXISTS (SELECT * FROM sys.tables WHERE name = N'DimProducts')
|
||||
DROP TABLE DimProducts;
|
||||
GO
|
||||
|
||||
CREATE TABLE DimProducts
|
||||
(
|
||||
[ProductID] INT NOT NULL,
|
||||
[Name] VARCHAR(50) NOT NULL,
|
||||
[Description] NVARCHAR(256) NULL
|
||||
)
|
||||
WITH
|
||||
(
|
||||
HEAP,
|
||||
DISTRIBUTION=ROUND_ROBIN
|
||||
);
|
||||
GO
|
||||
@@ -0,0 +1,13 @@
|
||||
1,Cables & Power,
|
||||
2,Camera & Photo,
|
||||
3,Cell Phones, That latest mobile devices.
|
||||
4,Computers,
|
||||
5,GPS & Navigation,
|
||||
6,Headphones,
|
||||
7,Home Audio,
|
||||
8,Office Electronics,
|
||||
9,Security & Survelliance,
|
||||
10,Software,
|
||||
11,Tablets, All of your tablet needs.
|
||||
12,Televisions, The latest in LCD/LED and 4K.
|
||||
13,Wearable Technology,
|
||||
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
|
||||
namespace BulkLoader
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
Load(args[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine("Error: {0}", e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
static void Load(string path)
|
||||
{
|
||||
// Load the file
|
||||
var reader = new StreamReader(path);
|
||||
|
||||
// Get the Data Table to hold the rows
|
||||
var datatable = GetDataTable();
|
||||
|
||||
// Setup our SQL Connection to our SQL Data Warehouse
|
||||
var connection = GetConnection();
|
||||
|
||||
// Iterate through the file
|
||||
string row;
|
||||
while ((row = reader.ReadLine()) != null)
|
||||
{
|
||||
// Split the row by comma
|
||||
var values = row.Split(',');
|
||||
|
||||
// Add the row values to the Data Table
|
||||
datatable.Rows.Add(values[0], values[1], values[2]);
|
||||
};
|
||||
|
||||
// Open the connection to SQL Data Warehouse
|
||||
connection.Open();
|
||||
|
||||
// Create a Bulk Copy class
|
||||
var bulkCopy = new SqlBulkCopy(connection);
|
||||
|
||||
// Define the target table
|
||||
bulkCopy.DestinationTableName = "dbo.DimProducts";
|
||||
|
||||
// Write the rows to the table
|
||||
bulkCopy.WriteToServer(datatable);
|
||||
|
||||
// Cleanup
|
||||
connection.Close();
|
||||
reader.Close();
|
||||
datatable.Dispose();
|
||||
}
|
||||
|
||||
static SqlConnection GetConnection()
|
||||
{
|
||||
var sb = new SqlConnectionStringBuilder();
|
||||
sb.DataSource = "##LOGICAL SQL SERVER##.database.windows.net";
|
||||
sb.InitialCatalog = "##DATABASE##";
|
||||
sb.UserID = "##USERNAME##";
|
||||
sb.Password = "##PASSWORD##";
|
||||
|
||||
return new SqlConnection(sb.ConnectionString);
|
||||
|
||||
}
|
||||
|
||||
static DataTable GetDataTable()
|
||||
{
|
||||
var dt = new DataTable();
|
||||
dt.Columns.AddRange
|
||||
(
|
||||
new DataColumn[3]
|
||||
{
|
||||
new DataColumn("ProductId", typeof(int)),
|
||||
new DataColumn("Name", typeof(string)),
|
||||
new DataColumn("Description", typeof(string))
|
||||
}
|
||||
);
|
||||
|
||||
return dt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
# SQL Bulk Copy Sample
|
||||
This code sample demonstrates how to load an Azure SQL Data Warehouse using the .NET [SqlBulkCopy class](https://msdn.microsoft.com/library/system.data.sqlclient.sqlbulkcopy.aspx).
|
||||
|
||||
### Contents
|
||||
|
||||
[About this sample](#about-this-sample)<br/>
|
||||
[Before you begin](#before-you-begin)<br/>
|
||||
[Disclaimers](#disclaimers)<br/>
|
||||
[Related links](#related-links)<br/>
|
||||
|
||||
<a name=about-this-sample></a>
|
||||
|
||||
## About this sample
|
||||
|
||||
1. **Applies to:** SQL Server 2012 (or higher) Enterprise / Developer / Evaluation Edition, Azure SQL Database, Azure SQL Data Warehouse
|
||||
2. **Key features:**
|
||||
- Bulk Loading via .NET
|
||||
3. **Workload:** Data Loading
|
||||
4. **Programming Language:** .NET C#, T-SQL
|
||||
5. **Authors:** Matt Usher [TwoUnder]
|
||||
|
||||
<a name=before-you-begin></a>
|
||||
|
||||
## Before you begin
|
||||
|
||||
To run this sample, you need the following prerequisites.
|
||||
|
||||
**Software prerequisites:**
|
||||
|
||||
1. SQL Server 2012 (or higher), an Azure SQL Database, or an Azure SQL Data Warehouse.
|
||||
2. Visual Studio 2015 (or higher).
|
||||
|
||||
<a name=disclaimers></a>
|
||||
|
||||
## Disclaimers
|
||||
The code included in this sample is not intended to be a set of best practices on how to build scalable enterprise grade applications. This is beyond the scope of this quick start sample.
|
||||
|
||||
<a name=related-links></a>
|
||||
|
||||
## Related Links
|
||||
<!-- Links to more articles. Remember to delete "en-us" from the link path. -->
|
||||
|
||||
For more information, see these articles:
|
||||
- [Azure SQL Data Warehouse] (http://aka.ms/sqldw)
|
||||
Reference in New Issue
Block a user