forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlServerDbFileHandler.cs
More file actions
35 lines (30 loc) · 1.62 KB
/
SqlServerDbFileHandler.cs
File metadata and controls
35 lines (30 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Globalization;
using System.IO;
namespace WebMatrix.Data
{
internal class SqlServerDbFileHandler : IDbFileHandler
{
private const string SqlServerConnectionStringFormat = @"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Initial Catalog={1};Integrated Security=True;User Instance=True;MultipleActiveResultSets=True";
private const string SqlServerProviderName = "System.Data.SqlClient";
public IConnectionConfiguration GetConnectionConfiguration(string fileName)
{
return new ConnectionConfiguration(SqlServerProviderName, GetConnectionString(fileName, Database.DataDirectory));
}
internal static string GetConnectionString(string fileName, string dataDirectory)
{
if (Path.IsPathRooted(fileName))
{
// Attach the db as the file name if it is rooted
return String.Format(CultureInfo.InvariantCulture, SqlServerConnectionStringFormat, fileName, fileName);
}
// Use |DataDirectory| if the path isn't rooted
string dataSource = @"|DataDirectory|\" + Path.GetFileName(fileName);
// Set the full path for the initial catalog so we attach as that
string initialCatalog = Path.Combine(dataDirectory, Path.GetFileName(fileName));
return String.Format(CultureInfo.InvariantCulture, SqlServerConnectionStringFormat, dataSource, initialCatalog);
}
}
}