Ejemplo n.º 1
0
        static public TypedDataSource GetFromConnectionUi(DataConnectionDialog connectionDialog)
        {
            TypedDataSource ds;

            if (connectionDialog.SelectedDataProvider == DataProvider.SqlDataProvider)
            {
                ds = new SqlDataSource();
            }
            else if (connectionDialog.SelectedDataProvider == DataProvider.OleDBDataProvider)
            {
                ds = new OleDbDataSource();
            }
            else if (connectionDialog.SelectedDataProvider == DataProvider.OdbcDataProvider)
            {
                ds = new OdbcDataSource();
            }
            else if (connectionDialog.SelectedDataProvider == DataProvider.OracleDataProvider)
            {
                ds = new OracleDataSource();
            }
            else
            {
                ds = new OtherDataSource();
            }
            ds.ProviderString = connectionDialog.ConnectionString;

            return(ds);
        }
Ejemplo n.º 2
0
        static public TypedDataSource GetFromTabularDs(TOMWrapper.ProviderDataSource tabularDataSource)
        {
            TypedDataSource ds;
            var             csb = new DbConnectionStringBuilder()
            {
                ConnectionString = tabularDataSource.ConnectionString
            };
            var providerName = !string.IsNullOrWhiteSpace(tabularDataSource.Provider) ? tabularDataSource.Provider : csb.ContainsKey("Provider") ? csb["Provider"].ToString() : "";
            var pName        = providerName.ToUpper();

            if (pName.Contains("MSADSQL") || pName.Contains("OLEDB"))
            {
                ds = new OleDbDataSource();
            }
            else if (pName.Contains("SQLNCLI") || pName.Contains("SQLCLIENT"))
            {
                ds = new SqlDataSource();
            }
            else if (pName.Contains("ODBC"))
            {
                ds = new OdbcDataSource();
            }
            else if (pName.Contains("ORACLE"))
            {
                ds = new OracleDataSource();
            }
            else
            {
                ds = new OtherDataSource();
            }

            ds.TabularDsName  = tabularDataSource.Name;
            ds.ProviderString = tabularDataSource.ConnectionString;

            return(ds);
        }
Ejemplo n.º 3
0
        static public TypedDataSource GetFromTabularDs(TOMWrapper.ProviderDataSource tabularDataSource)
        {
            TypedDataSource ds;
            bool            needsPassword = false;
            string          cs            = tabularDataSource.ConnectionString;

            if (!string.IsNullOrWhiteSpace(tabularDataSource.GetPreviewConnectionString()))
            {
                cs = tabularDataSource.GetPreviewConnectionString();
            }
            var csb = new DbConnectionStringBuilder()
            {
                ConnectionString = cs
            };

            if (!string.IsNullOrEmpty(tabularDataSource.Password) && tabularDataSource.Password != "********")
            {
                csb.Add("password", tabularDataSource.Password);
                csb.Add("user id", tabularDataSource.Account);
            }

            if (csb.ContainsKey("password") && (string)csb["password"] == "********")
            {
                if (GlobalPasswords.TryGetValue(tabularDataSource.ConnectionString, out string password))
                {
                    csb["password"] = password;
                }
                else
                {
                    needsPassword = true;
                }
            }
            if (csb.ContainsKey("pwd") && (string)csb["pwd"] == "********")
            {
                if (GlobalPasswords.TryGetValue(tabularDataSource.ConnectionString, out string password))
                {
                    csb["pwd"] = password;
                }
                else
                {
                    needsPassword = true;
                }
            }

            var providerName = !string.IsNullOrWhiteSpace(tabularDataSource.Provider) ? tabularDataSource.Provider : csb.ContainsKey("Provider") ? csb["Provider"].ToString() : "";
            var pName        = providerName.ToUpper();

            if (pName.Contains("MSADSQL") || pName.Contains("OLEDB"))
            {
                ds = new OleDbDataSource();
            }
            else if (pName.Contains("SQLNCLI") || pName.Contains("SQLCLIENT"))
            {
                ds = new SqlDataSource();
            }
            else if (pName.Contains("ODBC"))
            {
                ds = new OdbcDataSource();
            }
            else if (pName.Contains("ORACLE"))
            {
                ds = new OracleDataSource();
            }
            else
            {
                ds = new OtherDataSource();
            }

            ds.NeedsPassword = needsPassword;
            if (needsPassword)
            {
                ds.MissingPwdConnectionString = tabularDataSource.ConnectionString;
            }
            ds.TabularDsName = tabularDataSource.Name;

            ds.ProviderString = string.Join(";", csb.Keys.OfType <string>().Select(k => k + "=" + csb[k].ToString()).ToArray());

            if (!string.IsNullOrEmpty(tabularDataSource.Account))
            {
                ds.Username = tabularDataSource.Account;
            }
            else
            {
                if (csb.ContainsKey("user id"))
                {
                    ds.Username = csb["user id"].ToString();
                }
                else if (csb.ContainsKey("uid"))
                {
                    ds.Username = csb["uid"].ToString();
                }
                else if (csb.ContainsKey("username"))
                {
                    ds.Username = csb["username"].ToString();
                }
                else if (csb.ContainsKey("account"))
                {
                    ds.Username = csb["account"].ToString();
                }
            }



            return(ds);
        }