3
3
using System . Data . Odbc ;
4
4
using System . Data . SqlClient ;
5
5
#if NETFX
6
+ using System . Data . Common ;
6
7
using System . Data . SqlServerCe ;
7
8
using System . Data . SQLite ;
9
+ using System . Diagnostics ;
8
10
#endif
9
11
using System . IO ;
10
12
using FirebirdSql . Data . FirebirdClient ;
@@ -30,7 +32,8 @@ public class DatabaseSetup
30
32
{ "NHibernate.Driver.OdbcDriver" , SetupSqlServerOdbc } ,
31
33
#if NETFX
32
34
{ "NHibernate.Driver.SQLite20Driver" , SetupSQLite } ,
33
- { "NHibernate.Driver.SqlServerCeDriver" , SetupSqlServerCe }
35
+ { "NHibernate.Driver.SqlServerCeDriver" , SetupSqlServerCe } ,
36
+ { "NHibernate.Driver.SapSQLAnywhere17Driver" , SetupSqlAnywhere } ,
34
37
#endif
35
38
} ;
36
39
@@ -241,6 +244,57 @@ private static void SetupOracle(Cfg.Configuration cfg)
241
244
// }
242
245
//}
243
246
}
247
+
248
+ #if NETFX
249
+ private static void SetupSqlAnywhere ( Cfg . Configuration cfg )
250
+ {
251
+ var connStr = cfg . Properties [ Cfg . Environment . ConnectionString ] ;
252
+
253
+ var factory = DbProviderFactories . GetFactory ( "Sap.Data.SQLAnywhere" ) ;
254
+ var connBuilder = factory . CreateConnectionStringBuilder ( ) ;
255
+ connBuilder . ConnectionString = connStr ;
256
+ var filename = ( string ) connBuilder [ "DBF" ] ;
257
+
258
+ RunProcess ( "dbstop" , $ "-c \" UID=nhibernate;PWD=nhibernate;DBN=nhibernate\" -d", false ) ;
259
+ RunProcess ( "dberase" , $ "-y { filename } ", false ) ;
260
+ // -dba: login,pwd
261
+ RunProcess ( "dbinit" , $ "-dba nhibernate,nhibernate { filename } ", true ) ;
262
+
263
+ using ( var conn = factory . CreateConnection ( ) )
264
+ {
265
+ conn . ConnectionString = connStr ;
266
+ conn . Open ( ) ;
267
+ using ( var cmd = conn . CreateCommand ( ) )
268
+ {
269
+ cmd . CommandText = "set option ansi_update_constraints = 'Off'" ;
270
+ cmd . ExecuteNonQuery ( ) ;
271
+ }
272
+ }
273
+ }
274
+
275
+ private static void RunProcess ( string processName , string arguments , bool checkSuccess )
276
+ {
277
+ using ( var process = new Process ( ) )
278
+ {
279
+ process . StartInfo . FileName = processName ;
280
+ process . StartInfo . Arguments = arguments ;
281
+ process . StartInfo . CreateNoWindow = true ;
282
+ process . StartInfo . UseShellExecute = false ;
283
+ process . StartInfo . RedirectStandardOutput = true ;
284
+ process . StartInfo . RedirectStandardError = true ;
285
+ process . Start ( ) ;
286
+ Console . WriteLine ( $ "{ processName } output:") ;
287
+ Console . Write ( process . StandardOutput . ReadToEnd ( ) ) ;
288
+ Console . WriteLine ( ) ;
289
+ Console . WriteLine ( $ "{ processName } error output:") ;
290
+ Console . Write ( process . StandardError . ReadToEnd ( ) ) ;
291
+ Console . WriteLine ( ) ;
292
+ process . WaitForExit ( ) ;
293
+ if ( checkSuccess && process . ExitCode != 0 )
294
+ throw new InvalidOperationException ( $ "{ processName } has failed") ;
295
+ }
296
+ }
297
+ #endif
244
298
}
245
299
}
246
300
0 commit comments