Exemplo n.º 1
0
        public SQLLocalDatabase()
        {
            DbType = new SqlServer2012DatabaseType();
            DBPath = Environment.CurrentDirectory;

            FQDBFile = DBPath + "\\" + DBFileName;
            FQLogFile = DBPath + "\\" + LogFileName;

            ConnectionString = String.Format("Data Source=(LocalDB)\\v11.0;Integrated Security=True;AttachDbFileName=\"{0}\";", FQDBFile);
            ProviderName = "System.Data.SqlClient";

            RecreateDataBase();
            EnsureSharedConnectionConfigured();

            Console.WriteLine("Tables (Constructor): " + Environment.NewLine);
            var dt = ((SqlConnection)Connection).GetSchema("Tables");
            foreach (DataRow row in dt.Rows)
            {
                Console.WriteLine((string)row[2]);
            }
        }
Exemplo n.º 2
0
        public SQLLocalDatabase(string dataSource)
        {
            DbType = new SqlServer2012DatabaseType();
            DBPath = Directory.GetCurrentDirectory();

            FQDBFile = DBPath + "\\" + DBFileName;
            FQLogFile = DBPath + "\\" + LogFileName;

            ConnectionStringBase = String.Format("Data Source={0};Integrated Security=True;", dataSource);
            ConnectionString = String.Format("{0}AttachDbFileName=\"{1}\";", ConnectionStringBase, FQDBFile);
            ProviderName = "System.Data.SqlClient";

            RecreateDataBase();
            EnsureSharedConnectionConfigured();

            //            Console.WriteLine("Tables (Constructor): " + Environment.NewLine);
            //#if !DNXCORE50
            //            var dt = ((SqlConnection)Connection).GetSchema("Tables");
            //            foreach (DataRow row in dt.Rows)
            //            {
            //                Console.WriteLine((string)row[2]);
            //            }
            //#endif
        }
Exemplo n.º 3
0
        public void ConstructorWithConnectionStringAndDBProvider()
        {
            var dbType = new SqlServer2012DatabaseType();
            var provider = DbProviderFactories.GetFactory(dbType.GetProviderName());
            var db = new Database(TestDatabase.ConnectionString, provider);
            db.OpenSharedConnection();
            Assert.IsNotNull(db.Connection);
            Assert.IsTrue(db.Connection.State == ConnectionState.Open);
            Assert.AreEqual(typeof(SqlServerDatabaseType), db.DatabaseType.GetType());

            // Constructors using a Connection do not close the connection on close/displose
            db.CloseSharedConnection();
            Assert.IsNull(db.Connection);

            db.Dispose();
            Assert.IsNull(db.Connection);
        }