private SqlConnection GetConnection()
        {
            if (_connection == null)
            {
                _connection = new SqlConnection(@"Server=TestDataWindows\SQLEXPRESS;Database=osmsharp;User Id=osmsharp;Password=osmsharp;");
                _connection.Open();

                SQLServerSchemaTools.Remove(_connection);
            }
            return(_connection);
        }
Пример #2
0
        /// <summary>
        /// Creates a new/gets the existing connection.
        /// </summary>
        /// <returns></returns>
        private SqlConnection CreateConnection()
        {
            if (_connection == null)
            {
                _connection = new SqlConnection(_connectionString);
                _connection.Open();

                if (_createAndDetectSchema)
                { // creates or detects the tables.
                    SQLServerSchemaTools.CreateAndDetect(_connection);
                }
            }
            return(_connection);
        }
Пример #3
0
        /// <summary>
        /// Initializes the target.
        /// </summary>
        public override void Initialize()
        {
            if (_connection == null)
            {
                _connection = new SqlConnection(_connectionString);
                _connection.Open();
            }

            if (_createAndDetectSchema)
            {
                // creates or detects the tables.
                SQLServerSchemaTools.CreateAndDetect(_connection);
            }

            CreateNodeTables();
            CreateWayTables();
            CreateRelationTables();
        }
Пример #4
0
        /// <summary>
        /// Closes the current target.
        /// </summary>
        public override void Close()
        {
            if (_connection != null)
            {
                if (_createAndDetectSchema)
                {
                    // Adds constraints
                    SQLServerSchemaTools.AddConstraints(_connection);
                }

                if (!string.IsNullOrWhiteSpace(_connectionString))
                {
                    _connection.Close();
                    _connection.Dispose();
                    OsmSharp.Logging.Log.TraceEvent("OsmSharp.Data.SQLServer.Osm.Streams.SQLServerOsmStreamTarget", System.Diagnostics.TraceEventType.Information,
                                                    "Database connection closed");
                }
            }
            _connection = null;
        }