コード例 #1
0
        /// <summary>
        /// 获得数据库连接
        /// </summary>
        public static IDbConnection GetCon(SqliteDBName nameType)
        {
            var databaseName = nameType.ToString();

            if (!OrmLiteConnectionFactory.NamedConnections.ContainsKey(databaseName))
            {
                var connStr = string.Format(sqlConnectFormatter, databaseName, "192.168.1.60", "root", "");
                factory.RegisterConnection(databaseName, connStr, MySqlDialect.Provider);
            }

            return(factory.Open(databaseName));
        }
コード例 #2
0
        /// <summary>
        /// 获得数据库连接
        /// </summary>
        public static IDbConnection GetCon(SqliteDBName nameType)
        {
            var sqliteName = nameType + ".sqlite";

            if (!OrmLiteConnectionFactory.NamedConnections.ContainsKey(sqliteName))
            {
                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "db");

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

                var sqliteFileName = Path.Combine(path, sqliteName);
                factory.RegisterConnection(sqliteName, sqliteFileName, SqliteDialect.Provider);
            }

            return(factory.Open(sqliteName));
        }