Пример #1
0
        private static string GetConnectionStringHeader(string provider, ConnectionStringHeaderType headerType, string value)
        {
            if (provider == "SQLOLEDB" || String.IsNullOrEmpty(provider))
            {
                switch (headerType)
                {
                    case ConnectionStringHeaderType.Provider: return "Provider=SQLOLEDB;";
                    case ConnectionStringHeaderType.Server: return String.Format(CultureInfo.InvariantCulture, "Data Source={0};", value);
                    case ConnectionStringHeaderType.Database: return String.Format(CultureInfo.InvariantCulture, "Initial Catalog={0};", value);
                    case ConnectionStringHeaderType.Username: return String.Format(CultureInfo.InvariantCulture, "User Id={0};", value);
                    case ConnectionStringHeaderType.Password: return String.Format(CultureInfo.InvariantCulture, "Password={0};", value);
                    case ConnectionStringHeaderType.Trusted: return "Integrated Security=SSPI;";
                    case ConnectionStringHeaderType.MarsConnection: return String.Format(CultureInfo.InvariantCulture,"MARS Connection={0};", value);
                }
            }
            else if (provider == "SQLNCLI10" || provider == "SQLNCLI10.1" || provider == "SQLNCLI")
            {
                switch (headerType)
                {
                    case ConnectionStringHeaderType.Provider: return String.Format(CultureInfo.InvariantCulture, "Provider={0};", provider);
                    case ConnectionStringHeaderType.Server: return String.Format(CultureInfo.InvariantCulture, "Data Source={0};", value);
                    case ConnectionStringHeaderType.Database: return String.Format(CultureInfo.InvariantCulture, "Initial Catalog={0};", value);
                    case ConnectionStringHeaderType.Username: return String.Format(CultureInfo.InvariantCulture, "User ID={0};", value);
                    case ConnectionStringHeaderType.Password: return String.Format(CultureInfo.InvariantCulture, "Password={0};", value);
                    case ConnectionStringHeaderType.Trusted: return "Trusted_Connection=yes;Integrated Security=SSPI;";
                    case ConnectionStringHeaderType.MarsConnection: return String.Format(CultureInfo.InvariantCulture,"MARS Connection={0};", value);
                }
            }
            else if (provider == "{SQL Server Native Client 10.0}" || provider == "{SQL Native Client}")
            {
                switch (headerType)
                {
                    case ConnectionStringHeaderType.Provider: return String.Format(CultureInfo.InvariantCulture, "Driver={0};", provider);
                    case ConnectionStringHeaderType.Server: return String.Format(CultureInfo.InvariantCulture, "Server={0};", value);
                    case ConnectionStringHeaderType.Database: return String.Format(CultureInfo.InvariantCulture, "Database={0};", value);
                    case ConnectionStringHeaderType.Username: return String.Format(CultureInfo.InvariantCulture, "UId={0};", value);
                    case ConnectionStringHeaderType.Password: return String.Format(CultureInfo.InvariantCulture, "Pwd={0};", value);
                    case ConnectionStringHeaderType.Trusted: return "Trusted_Connection=yes;";
                    case ConnectionStringHeaderType.MarsConnection: return String.Format(CultureInfo.InvariantCulture,"MARS Connection={0};", value);
                }
            }
            else if (provider == "SQLXMLOLEDB")
            {
            }
            else if (provider == "Microsoft.ACE.OLEDB.12.0" || provider == "Microsoft.Jet.OLEDB.4.0")
            {
                switch (headerType)
                {
                    case ConnectionStringHeaderType.Provider: return String.Format(CultureInfo.InvariantCulture, "Provider={0};", provider);
                    case ConnectionStringHeaderType.Server: return String.Format(CultureInfo.InvariantCulture, "Data Source={0};", value);

                    case ConnectionStringHeaderType.PersistSecurityInfo: return String.Format(CultureInfo.InvariantCulture, "Persist Security Info={0};", value);
                    case ConnectionStringHeaderType.AdditionalParameters: return String.Format(CultureInfo.InvariantCulture, "Extended Properties=\"{0}\";", value);
                }
            }

            return null;
        }
Пример #2
0
        private static string GetConnectionStringHeader(string provider, ConnectionStringHeaderType headerType, string value)
        {
            if (provider == "SQLOLEDB" || String.IsNullOrEmpty(provider))
            {
                switch (headerType)
                {
                case ConnectionStringHeaderType.Provider: return("Provider=SQLOLEDB;");

                case ConnectionStringHeaderType.Server: return(String.Format(CultureInfo.InvariantCulture, "Data Source={0};", value));

                case ConnectionStringHeaderType.Database: return(String.Format(CultureInfo.InvariantCulture, "Initial Catalog={0};", value));

                case ConnectionStringHeaderType.Username: return(String.Format(CultureInfo.InvariantCulture, "User Id={0};", value));

                case ConnectionStringHeaderType.Password: return(String.Format(CultureInfo.InvariantCulture, "Password={0};", value));

                case ConnectionStringHeaderType.Trusted: return("Integrated Security=SSPI;");

                case ConnectionStringHeaderType.MarsConnection: return(String.Format(CultureInfo.InvariantCulture, "MARS Connection={0};", value));
                }
            }
            else if (provider == "SQLNCLI10" || provider == "SQLNCLI10.1" || provider == "SQLNCLI")
            {
                switch (headerType)
                {
                case ConnectionStringHeaderType.Provider: return(String.Format(CultureInfo.InvariantCulture, "Provider={0};", provider));

                case ConnectionStringHeaderType.Server: return(String.Format(CultureInfo.InvariantCulture, "Data Source={0};", value));

                case ConnectionStringHeaderType.Database: return(String.Format(CultureInfo.InvariantCulture, "Initial Catalog={0};", value));

                case ConnectionStringHeaderType.Username: return(String.Format(CultureInfo.InvariantCulture, "User ID={0};", value));

                case ConnectionStringHeaderType.Password: return(String.Format(CultureInfo.InvariantCulture, "Password={0};", value));

                case ConnectionStringHeaderType.Trusted: return("Trusted_Connection=yes;Integrated Security=SSPI;");

                case ConnectionStringHeaderType.MarsConnection: return(String.Format(CultureInfo.InvariantCulture, "MARS Connection={0};", value));
                }
            }
            else if (provider == "{SQL Server Native Client 10.0}" || provider == "{SQL Native Client}")
            {
                switch (headerType)
                {
                case ConnectionStringHeaderType.Provider: return(String.Format(CultureInfo.InvariantCulture, "Driver={0};", provider));

                case ConnectionStringHeaderType.Server: return(String.Format(CultureInfo.InvariantCulture, "Server={0};", value));

                case ConnectionStringHeaderType.Database: return(String.Format(CultureInfo.InvariantCulture, "Database={0};", value));

                case ConnectionStringHeaderType.Username: return(String.Format(CultureInfo.InvariantCulture, "UId={0};", value));

                case ConnectionStringHeaderType.Password: return(String.Format(CultureInfo.InvariantCulture, "Pwd={0};", value));

                case ConnectionStringHeaderType.Trusted: return("Trusted_Connection=yes;");

                case ConnectionStringHeaderType.MarsConnection: return(String.Format(CultureInfo.InvariantCulture, "MARS Connection={0};", value));
                }
            }
            else if (provider == "SQLXMLOLEDB")
            {
            }
            else if (provider == "Microsoft.ACE.OLEDB.12.0" || provider == "Microsoft.Jet.OLEDB.4.0")
            {
                switch (headerType)
                {
                case ConnectionStringHeaderType.Provider: return(String.Format(CultureInfo.InvariantCulture, "Provider={0};", provider));

                case ConnectionStringHeaderType.Server: return(String.Format(CultureInfo.InvariantCulture, "Data Source={0};", value));

                case ConnectionStringHeaderType.PersistSecurityInfo: return(String.Format(CultureInfo.InvariantCulture, "Persist Security Info={0};", value));

                case ConnectionStringHeaderType.AdditionalParameters: return(String.Format(CultureInfo.InvariantCulture, "Extended Properties=\"{0}\";", value));
                }
            }

            return(null);
        }