Example #1
0
        //连接本地,请注意可能需要指定this.DbInteractiveArgs = {返回值}
        public bool Connect(string dbName, string userName, string pwd)
        {
            String localhostConstr = "server =localhost; database ={0}; user={1}; password = {2};Charset=utf8;pooling=True;minpoolsize=1;maxpoolsize=100";

            String       connectstring = String.Format(localhostConstr, "mysql", userName, pwd);
            DbConnection dbconnection  = GetDbConnection();

            dbconnection.ConnectionString = connectstring;
            if (!this.Connect(dbconnection))
            {
                return(false);
            }
            List <String> allDBNames = this.GetAllDBNames()?.ToList();
            bool          b          = allDBNames.Contains(dbName.ToLower());

            if (!b)
            {
                NewDB(dbName);
            }

            ThisDbPipeInfo.Dispose();
            ThisDbPipeInfo = null;
            connectstring  = String.Format(localhostConstr, dbName, userName, pwd);
            dbconnection   = GetDbConnection();
            dbconnection.ConnectionString = connectstring;
            b = this.Connect(dbconnection);
            return(b);
        }
Example #2
0
        //远程连接,请注意可能需要指定this.DbInteractiveArgs = {返回值}
        public bool Connect(string ip, int port, string dbName, string userName, string pwd)
        {
            String connectstring = String.Format(
                "server={0};user={1};database=mysql;port={2};password={3};Charset=utf8;"
                , ip, userName, port, pwd);

            DbConnection dbconnection = GetDbConnection();

            dbconnection.ConnectionString = connectstring;
            bool bconn = this.Connect(dbconnection);

            if (bconn)
            {
                List <String> allDBNames = this.GetAllDBNames()?.ToList();
                bool          b          = allDBNames.Contains(dbName.ToLower());
                if (!b)
                {
                    NewDB(dbName);
                }
                ThisDbPipeInfo.Dispose();
                ThisDbPipeInfo = null;
                connectstring  = String.Format("server ={0}; database ={1}; user={2}; password = {3};Charset=utf8", ip,
                                               dbName, userName, pwd);
                dbconnection = GetDbConnection();
                dbconnection.ConnectionString = connectstring;
                bconn = this.Connect(dbconnection);
            }

            return(bconn);
        }
Example #3
0
        /// <summary>
        /// 连接到Postgresql
        /// </summary>
        public bool Connect(String ip, int port, string dbName, string userName, string pwd)
        {
            if (!ShikiiDBExist)
            {
                //String ip,string dbName, string userName, string pwd,int port)
                bool b = InternalConnect(ip, "postgres", "postgres", pwd, port);

                if (b)
                {
                    List <String> allDBNames = this.GetAllDBNames( );
                    b = allDBNames.Contains(dbName.ToLower());
                    if (!b)
                    {
                        NewDB(dbName);
                    }
                    ThisDbPipeInfo.Dispose();
                    ThisDbPipeInfo = null;

                    b             = InternalConnect(ip, dbName, userName, pwd, port);
                    ShikiiDBExist = true;
                }
                return(b);
            }
            else
            {
                bool b = InternalConnect("localhost", dbName, userName, pwd, port);

                return(b);
            }
        }