public static void SetDefaultConnectionString(string cTestdataTxt) { _connectionString = cTestdataTxt; if (string.IsNullOrEmpty(_connectionString) || _connectionString.EndsWith(".txt")) { _textFileWorkspace = GetTextFileWorkspace(); } }
public static void UpdateConnection(string connectionString) { _connectionString = connectionString; Database.SetInitializer(new Initializer()); if (string.IsNullOrEmpty(_connectionString)) { if (LocalSettings.IsSqlce40Installed()) { _connectionString = string.Format("data source={0}\\{1}.sdf", LocalSettings.DocumentPath, LocalSettings.AppName); } else { _connectionString = GetTextFileName(); } } if (_connectionString.EndsWith(".sdf")) { if (!_connectionString.ToLower().Contains("data source") && !_connectionString.Contains(":\\")) { _connectionString = string.Format("data source={0}\\{1}", LocalSettings.DocumentPath, _connectionString); } Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "", _connectionString); } else if (_connectionString.EndsWith(".txt")) { _textFileWorkspace = GetTextFileWorkspace(); } else if (!string.IsNullOrEmpty(_connectionString)) { var cs = _connectionString; if (!cs.Trim().EndsWith(";")) { cs += ";"; } if (!cs.ToLower().Contains("multipleactiveresultsets")) { cs += " MultipleActiveResultSets=True;"; } if (!cs.ToLower(CultureInfo.InvariantCulture).Contains("user id") && (!cs.ToLower(CultureInfo.InvariantCulture).Contains("integrated security"))) { cs += " Integrated Security=True;"; } if (cs.ToLower(CultureInfo.InvariantCulture).Contains("user id") && !cs.ToLower().Contains("persist security info")) { cs += " Persist Security Info=True;"; } Database.DefaultConnectionFactory = new SqlConnectionFactory(cs); } }
static WorkspaceFactory() { Database.SetInitializer(new Initializer()); if (string.IsNullOrEmpty(LocalSettings.ConnectionString)) { if (IsSqlce40Installed()) { LocalSettings.ConnectionString = "data source=" + LocalSettings.DocumentPath + "\\SambaData2.sdf"; } else { LocalSettings.ConnectionString = GetTextFileName(); } } if (LocalSettings.ConnectionString.EndsWith(".sdf")) { Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "", LocalSettings.ConnectionString); } else if (LocalSettings.ConnectionString.EndsWith(".txt")) { _textFileWorkspace = GetTextFileWorkspace(); } else if (_connectionString.StartsWith("mongodb://")) { MongoWorkspace = GetMongoWorkspace(); } else if (!string.IsNullOrEmpty(LocalSettings.ConnectionString)) { var cs = LocalSettings.GetSqlServerConnectionString(); if (!cs.Trim().EndsWith(";")) { cs += ";"; } if (!cs.ToLower().Contains("multipleactiveresultsets")) { cs += " MultipleActiveResultSets=True;"; } if (!cs.ToLower(CultureInfo.InvariantCulture).Contains("user id") && (!cs.ToLower(CultureInfo.InvariantCulture).Contains("integrated security"))) { cs += " Integrated Security=True;"; } if (cs.ToLower(CultureInfo.InvariantCulture).Contains("user id") && !cs.ToLower().Contains("persist security info")) { cs += " Persist Security Info=True;"; } Database.DefaultConnectionFactory = new SqlConnectionFactory(cs); } }