forked from aspnetwebstack/aspnetwebstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlCeDbFileHandler.cs
More file actions
36 lines (30 loc) · 1.38 KB
/
SqlCeDbFileHandler.cs
File metadata and controls
36 lines (30 loc) · 1.38 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
36
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
namespace WebMatrix.Data
{
internal class SqlCeDbFileHandler : IDbFileHandler
{
private const string SqlCeConnectionStringFormat = @"Data Source={0};File Access Retry Timeout=10";
public IConnectionConfiguration GetConnectionConfiguration(string fileName)
{
// Get the default provider name
string providerName = Database.GetDefaultProviderName();
Debug.Assert(!String.IsNullOrEmpty(providerName), "Provider name should not be null or empty");
string connectionString = GetConnectionString(fileName);
return new ConnectionConfiguration(providerName, connectionString);
}
public static string GetConnectionString(string fileName)
{
if (Path.IsPathRooted(fileName))
{
return String.Format(CultureInfo.InvariantCulture, SqlCeConnectionStringFormat, fileName);
}
// Use |DataDirectory| if the path isn't rooted
string dataSource = @"|DataDirectory|\" + Path.GetFileName(fileName);
return String.Format(CultureInfo.InvariantCulture, SqlCeConnectionStringFormat, dataSource);
}
}
}