internal static void CreateDatabaseObjects(IDbConnection conn, string schema, string tableName, FeatureDataTable model, out string oidColumn, out string geometryColumn) { SqlServerDbUtility util = new SqlServerDbUtility(); string oidCol = model.PrimaryKey[0].ColumnName, geomCol = "Geom"; StringBuilder sb = new StringBuilder(); sb.AppendFormat("CREATE TABLE [{0}].[{1}] (", schema, tableName); foreach (DataColumn column in model.Columns) { sb.AppendFormat("[{0}] {1},\n", column.ColumnName, SqlServerDbUtility.GetFullTypeString(column.DataType)); } sb.Append("\n[Geom] geometry,"); sb.AppendFormat("CONSTRAINT [pk_{0}_{1}] PRIMARY KEY CLUSTERED([{1}])", tableName, oidCol); sb.AppendLine(")"); oidColumn = oidCol; geometryColumn = geomCol; IDbCommand cmd = conn.CreateCommand(); cmd.CommandText = sb.ToString(); ExecuteNoQuery(cmd); }
public IFeatureProvider ConstructSourceProvider(IGeometryServices geometryServices) { Console.WriteLine( "Please enter the connection string for the source server. Press Enter to use the following:"); Console.WriteLine(Settings.Default.SourceConnectionString); string connectionString = Console.ReadLine(); if (connectionString == "") { connectionString = Settings.Default.SourceConnectionString; } else { Settings.Default.SourceConnectionString = connectionString; } Settings.Default.Save(); Console.WriteLine("Please enter the data tables' schema"); string dtschema = Console.ReadLine(); Console.WriteLine("Please enter the table name."); string tableName = Console.ReadLine(); Console.WriteLine("Please enter the id column name. (CaSe sensitive)"); _oidColumn = Console.ReadLine(); Console.WriteLine("Please enter the geometry column name. (CaSe sensitive)"); string geometryColumn = Console.ReadLine(); Console.WriteLine("Please enter the SRID (e.g EPSG:4326)"); string srid = Console.ReadLine(); Type type; SqlServerDbUtility dbUtility = new SqlServerDbUtility(); using (IDbConnection conn = dbUtility.CreateConnection(connectionString)) { using (IDbCommand cmd = conn.CreateCommand()) { cmd.CommandText = string.Format("SELECT TOP 1 [{0}] FROM [{1}].[{2}] ", _oidColumn, dtschema, tableName); cmd.CommandType = CommandType.Text; conn.Open(); type = cmd.ExecuteScalar().GetType(); } } Type t = typeof(MsSqlServer2008Provider <>); Type specialized = t.MakeGenericType(type); _sourceProvider = (IFeatureProvider) Activator.CreateInstance(specialized, geometryServices[srid], connectionString, dtschema, tableName, _oidColumn, geometryColumn); _sourceProvider.Open(); _sourceProviderOidType = type; return(_sourceProvider); }
internal static MsSqlServer2008Provider <TOid> Create <TOid>(string connectionString, IGeometryFactory geometryFactory, string schema, string tableName, FeatureDataTable model) { using (IDbConnection conn = new SqlServerDbUtility().CreateConnection(connectionString)) { //using (IDbTransaction tran = conn.BeginTransaction()) //{ // try // { if (!EnsureDbIsSpatiallyEnabled(conn)) { throw new InvalidDatabaseConfigurationException( "Database does not contain spatial components."); } if (CheckIfObjectExists(conn, schema, tableName)) { MsSqlServer2008Provider <TOid> provider; if (CheckProviderCompatibility(conn, geometryFactory, schema, tableName, model, out provider)) { return(provider); } throw new IncompatibleSchemaException( "The table already exists in the database but has an incompatible schema."); } string oidColumn, geometryColumn; CreateDatabaseObjects(conn, schema, tableName, model, out oidColumn, out geometryColumn); MsSqlServer2008Provider <TOid> prov = new MsSqlServer2008Provider <TOid>(geometryFactory, connectionString, schema, tableName, oidColumn, geometryColumn); // tran.Commit(); return(prov); //} //catch //{ // tran.Rollback(); // throw; //} //} } }
public IFeatureProvider ConstructSourceProvider(IGeometryServices geometryServices) { Console.WriteLine( "Please enter the connection string for the source server. Press Enter to use the following:"); Console.WriteLine(Settings.Default.SourceConnectionString); string connectionString = Console.ReadLine(); if (connectionString == "") connectionString = Settings.Default.SourceConnectionString; else Settings.Default.SourceConnectionString = connectionString; Settings.Default.Save(); Console.WriteLine("Please enter the data tables' schema"); string dtschema = Console.ReadLine(); Console.WriteLine("Please enter the table name."); string tableName = Console.ReadLine(); Console.WriteLine("Please enter the id column name. (CaSe sensitive)"); _oidColumn = Console.ReadLine(); Console.WriteLine("Please enter the geometry column name. (CaSe sensitive)"); string geometryColumn = Console.ReadLine(); Console.WriteLine("Please enter the SRID (e.g EPSG:4326)"); string srid = Console.ReadLine(); Type type; SqlServerDbUtility dbUtility = new SqlServerDbUtility(); using (IDbConnection conn = dbUtility.CreateConnection(connectionString)) { using (IDbCommand cmd = conn.CreateCommand()) { cmd.CommandText = string.Format("SELECT TOP 1 [{0}] FROM [{1}].[{2}] ", _oidColumn, dtschema, tableName); cmd.CommandType = CommandType.Text; conn.Open(); type = cmd.ExecuteScalar().GetType(); } } Type t = typeof (MsSqlServer2008Provider<>); Type specialized = t.MakeGenericType(type); _sourceProvider = (IFeatureProvider) Activator.CreateInstance(specialized, geometryServices[srid], connectionString, dtschema, tableName, _oidColumn, geometryColumn); _sourceProvider.Open(); _sourceProviderOidType = type; return _sourceProvider; }