Beispiel #1
0
        public virtual string GetConnection(string serverName, string catalog, bool?integratedSecurity, string username, string password, string duradosuserId, SqlProduct sqlProduct, int localPort, bool usesSsh, bool usesSsl)
        {
            string connectionString = null;

            System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();

            builder.ConnectionString = Map.connectionString;

            bool hasServer  = !string.IsNullOrEmpty(serverName);
            bool hasCatalog = !string.IsNullOrEmpty(catalog);


            if (!hasCatalog)
            {
                throw new DuradosException("Catalog Name is missing");
            }


            if (integratedSecurity.HasValue && integratedSecurity.Value)
            {
                if (!hasServer)
                {
                    serverName = builder.DataSource;
                }
                connectionString = "Data Source={0};Initial Catalog={1};Integrated Security=True;";
                return(string.Format(connectionString, serverName, catalog));
            }
            else
            {
                connectionString = "Data Source={0};Initial Catalog={1};User ID={2};Password={3};Integrated Security=False;";
                if (sqlProduct == SqlProduct.MySql)
                {
                    if (usesSsh)
                    {
                        connectionString = "server=localhost;database={1};User Id={2};password={3};port={4};convert zero datetime=True";
                    }
                    else
                    {
                        connectionString = "server={0};database={1};User Id={2};password={3};port={4};convert zero datetime=True";
                    }
                }
                if (sqlProduct == SqlProduct.Postgre)
                {
                    if (usesSsl)
                    {
                        if (usesSsh)
                        {
                            connectionString = "server=localhost;database={1};User Id={2};password={3};port={4};SSL=true;SslMode=Require;";
                        }
                        else
                        {
                            connectionString = "server={0};database={1};User Id={2};password={3};port={4};SSL=true;SslMode=Require;";
                        }
                    }
                    //connectionString = "HOST={0};DATABASE={1};USER ID={2};PASSWORD={3}";//test1.cb8bfk90dnws.us-west-2.rds.amazonaws.com;DATABASE=demo;USER ID=root;PASSWORD=Modubiz2012
                    else
                    if (usesSsh)
                    {
                        connectionString = "server=localhost;database={1};User Id={2};password={3};port={4};Encoding=UNICODE;";
                    }
                    else
                    {
                        connectionString = "server={0};database={1};User Id={2};password={3};port={4};Encoding=UNICODE;";
                    }
                    // connectionString = "HOST={0};DATABASE={1};USER ID={2};PASSWORD={3}";//
                }
                if (sqlProduct == SqlProduct.Oracle)
                {                                                                //"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT=1521))(CONNECT_DATA=(SERVICE_NAME={1})));User ID={2};Password={3};"
                    connectionString = OracleAccess.GetConnectionStringSchema(); // "server=localhost;database={1};User Id={2};password={3};port={4};convert zero datetime=True";
                }
                bool hasUsername = !string.IsNullOrEmpty(username);
                bool hasPassword = !string.IsNullOrEmpty(password);

                //if (!hasServer)
                //{
                //    if (Maps.AllowLocalConnection)
                //        serverName = builder.DataSource;
                //    else
                //        throw new DuradosException("Server Name is missing");
                //}

                //if (!hasUsername)
                //{
                //    if (Maps.AllowLocalConnection)
                //        username = builder.UserID;
                //    else
                //        throw new DuradosException("Username Name is missing");
                //}

                //if (!hasPassword)
                //{
                //    if (Maps.AllowLocalConnection)
                //        password = builder.Password;
                //    else
                //        throw new DuradosException("Password Name is missing");
                //}

                //return string.Format(connectionString, serverName, catalog, username, password);
                if (!hasServer)
                {
                    if (Maps.AllowLocalConnection)
                    {
                        serverName = builder.DataSource;
                    }
                    else
                    {
                        throw new DuradosException("Server Name is missing");
                    }
                }

                if (!hasUsername)
                {
                    if (Maps.AllowLocalConnection)
                    {
                        username = builder.UserID;
                    }
                    else
                    {
                        throw new DuradosException("Username is missing");
                    }
                }

                if (!hasPassword)
                {
                    if (Maps.AllowLocalConnection)
                    {
                        password = builder.Password;
                    }
                    else
                    {
                        throw new DuradosException("Password is missing");
                    }
                }

                return(string.Format(connectionString, serverName, catalog, username, password, localPort));
            }
        }
Beispiel #2
0
        public object GetOracleConnection(MapDataSet.durados_AppRow appRow, object builder, int localPort)
        {
            int  dataSourceTypeId = appRow.DataSourceTypeId;
            bool usesSsh          = !appRow.durados_SqlConnectionRowByFK_durados_App_durados_SqlConnection.IsSshUsesNull() && appRow.durados_SqlConnectionRowByFK_durados_App_durados_SqlConnection.SshUses;

            return(GetConnection(appRow.durados_SqlConnectionRowByFK_durados_App_durados_SqlConnection, dataSourceTypeId, (System.Data.SqlClient.SqlConnectionStringBuilder)builder, OracleAccess.GetConnectionStringSchema()));
        }