Changeset 8 for Common/Database.cs
- Timestamp:
- Aug 12, 2019, 12:33:47 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/Database.cs
r7 r8 28 28 public delegate void LogMessageHandler(string text); 29 29 public static event LogMessageHandler LogMessage; 30 public static string connectionString = "";31 30 public static string databaseName = ""; 32 31 public static string serverName = ""; … … 40 39 41 40 // Connect to server 42 if (type == DatabaseType.MsSql)43 {44 connectionString = "server=" + serverName + "; Trusted_Connection=yes; database=" + databaseName + "; connection timeout=5";45 } else46 41 if (type == DatabaseType.SQLite) 47 42 { 48 43 Directory.CreateDirectory(Path.GetDirectoryName(sqliteFileName)); 49 connectionString = "Data Source=" + sqliteFileName + "; Version=3";50 44 databaseName = null; 51 45 } … … 62 56 { 63 57 // database does not exist, try to create it 64 connectionString = "server=" + serverName + "; Trusted_Connection=yes; connection timeout=5";65 58 ExecuteNonQuery("CREATE DATABASE " + databaseName); 66 59 67 60 // Need to wait for the new DB startup in order to continue and be sure it can be accessed 68 61 if (connection is SqlConnection) SqlConnection.ClearAllPools(); 69 70 connectionString = "server=" + serverName + "; Trusted_Connection=yes; database=" + databaseName + "; connection timeout=5";71 62 } 72 63 else … … 87 78 88 79 return result; 80 } 81 82 public static string GetConnectionString() 83 { 84 string connectionString = ""; 85 if (type == DatabaseType.MsSql) 86 { 87 connectionString = "server=" + serverName + "; Trusted_Connection=yes; database=" + databaseName + "; connection timeout=5"; 88 } 89 else 90 if (type == DatabaseType.SQLite) 91 { 92 connectionString = "Data Source=" + sqliteFileName + "; Version=3"; 93 } 94 return connectionString; 89 95 } 90 96 … … 105 111 { 106 112 DbConnection connection = GetFactory().CreateConnection(); 107 connection.ConnectionString = connectionString;113 connection.ConnectionString = GetConnectionString(); 108 114 return connection; 109 115 }
Note:
See TracChangeset
for help on using the changeset viewer.