Exemplo n.º 1
0
        public void SetSession(SqlProviders pType, string sHost, string sPort = "", string sUser = "", string sPass = "", string sData = "")
        {
            switch (pType)
            {
                case SqlProviders.SqlServer:
                    dbFactory = SqlClientFactory.Instance;

                    sConnection = "Server=" + sHost + (sPort.Length > 0 ? "," + sPort : "");
                    if (sUser != "")
                    {
                        sConnection += ";User Id=" + sUser;
                        if (sPass != "")
                        {
                            sConnection += ";Password="******";Integrated Security=True;Trusted_Connection=True";
                    }

                    sConnection += ";Initial Catalog=" + sData + ";";
                    dbConnection = dbFactory.CreateConnection();
                    dbCommand = dbFactory.CreateCommand();
                    dbConnection.ConnectionString = sConnection;
                    dbCommand.Connection = dbConnection;
                    break;

                case SqlProviders.SQLite:
                    sqlFactory = SQLiteFactory.Instance;
                    sDbPathSQLite = sHost + @"\" + sDbFileSQLite;

                    if (!Directory.Exists(sHost))
                    {
                        Directory.CreateDirectory(sHost);
                    }

                    SQLiteConnectionStringBuilder sb = new SQLiteConnectionStringBuilder();
                    sb.DefaultTimeout = 5000;
                    sb.SyncMode = SynchronizationModes.Off;
                    sb.JournalMode = SQLiteJournalModeEnum.Memory;
                    sb.PageSize = 65536;
                    sb.CacheSize = 16777216;
                    sb.FailIfMissing = false;
                    sb.ReadOnly = false;

                    sConnection = "data source=" + @sDbPathSQLite + ";" + sb.ConnectionString;
                    sqlConnection = (SQLiteConnection)sqlFactory.CreateConnection();
                    sqlCommand = (SQLiteCommand)sqlFactory.CreateCommand();
                    sqlConnection.ConnectionString = sConnection;
                    sqlCommand.Connection = sqlConnection;
                    break;
            }
        }