コード例 #1
0
        public static PostgreSqlConn GetInstance(string server, string port, string initialDB, string username, string password)
        {
            if (instance == null)
            {
                instance = new PostgreSqlConn();
            }

            serverName = server;
            if (null != initialDB)
            {
                initDB = initialDB;
            }
            //trusted = trustedState;
            user = username;
            pw   = password;

            try
            {
                //connString = @"Server=" + server + (initDB != null ? @"\" + initDB : "") + ";Trusted_Connection=" + trusted + (trusted ? "" : ";User Id=" + user + ";Password="******";";
                connString = @"Server=" + server + @";DataBase=" + initDB + ";User Id=" + user + ";Password="******";Port=" + port + ";";
                dbConnStringBuilder.ConnectionString = connString;
                conn = new NpgsqlConnection(connString);
            }
            catch (ArgumentException e)
            {
                MessageBox.Show("Connection String Error! (" + e.Message + ")");
            }
            catch (InvalidOperationException e)
            {
                MessageBox.Show("Invalid Operation Error! (" + e.Message + ")");
            }

            return(instance);
        }
コード例 #2
0
        //public static IConnectionObject createMSSQLConnection()
        //{
        //    return
        //}
        internal static IConnectionObject createConnection(string provider, string server, string initDB, bool trusted, string username, string password, string port, string sid)
        {
            if (provider.Equals("PostgreSQL"))
            {
                return(PostgreSqlConn.GetInstance(server, port, initDB, username, password));
            }

            dbFactory = System.Data.Common.DbProviderFactories.GetFactory(providers[provider]);
            if (provider.Equals("Oracle"))
            {
                return(OracleConn.GetInstance(server, port, sid, username, password, dbFactory));
            }
            if (provider.Equals("MSSQL"))
            {
                return(DBConn.GetInstance(server, initDB, trusted, username, password, dbFactory));
            }
            throw new NotImplementedException();
        }