public static IDbConnection GetConnection(string provider, string cstring)
        {
            IDbConnection cn = null;

            switch (provider.ToLower())
            {
            case "sql":
                // can't connect unless information provided;
                //   when user wants to set the connection programmatically this they should do this
                if (cstring.Length > 0)
                {
                    cn = new SqlConnection(cstring);
                }
                break;

            case "odbc":
                cn = new OdbcConnection(cstring);
                break;

            case "oledb":
                cn = new OleDbConnection(cstring);
                break;

            case "filedirectory":
                cn = new fyiReporting.Data.FileDirConnection(cstring);
                break;

            case "xml":
                cn = new fyiReporting.Data.XmlConnection(cstring);
                break;

            case "webservice":
                cn = new fyiReporting.Data.WebServiceConnection(cstring);
                break;

            case "weblog":
                cn = new fyiReporting.Data.LogConnection(cstring);
                break;

            case "text":
                cn = new fyiReporting.Data.TxtConnection(cstring);
                break;

            case "itunes":
                cn = new fyiReporting.Data.iTunesConnection(cstring);
                break;

            default:
                if (SqlEntries == null)              // if never initialized; we should init
                {
                    RdlEngineConfigInit();
                }
                System.Console.WriteLine("Attempt to find provider");
                SqlConfigEntry sce = SqlEntries[provider] as SqlConfigEntry;
                if (sce == null || sce.CodeModule == null)
                {
                    if (sce != null && sce.ErrorMsg != null)        // error during initialization??
                    {
                        throw new Exception(sce.ErrorMsg);
                    }
                    break;
                }
                System.Console.WriteLine("Provider Create Instance");
                object[] args = new object[] { cstring };
                Assembly asm  = sce.CodeModule;
                object   o    = asm.CreateInstance(sce.ClassName, false,
                                                   BindingFlags.CreateInstance, null, args, null, null);
                if (o == null)
                {
                    throw new Exception(string.Format("Unable to create instance of '{0}' for provider '{1}'", sce.ClassName, provider));
                }
                cn = o as IDbConnection;
                break;
            }

            return(cn);
        }
Exemplo n.º 2
0
        public static IDbConnection GetConnection(string provider, string cstring)
        {
            IDbConnection cn = null;
            switch (provider.ToLower())
            {
                case "sql":
                    // can't connect unless information provided;
                    //   when user wants to set the connection programmatically this they should do this
                    if (cstring.Length > 0)
                        cn = new SqlConnection(cstring);
                    break;
                case "odbc":
                    cn = new OdbcConnection(cstring);
                    break;
                case "oledb":
                    cn = new OleDbConnection(cstring);
                    break;
                case "filedirectory":
                    cn = new fyiReporting.Data.FileDirConnection(cstring);
                    break;
                case "xml":
                    cn = new fyiReporting.Data.XmlConnection(cstring);
                    break;
                case "webservice":
                    cn = new fyiReporting.Data.WebServiceConnection(cstring);
                    break;
                case "weblog":
                    cn = new fyiReporting.Data.LogConnection(cstring);
                    break;
                case "text":
                    cn = new fyiReporting.Data.TxtConnection(cstring);
                    break;
                case "itunes":
                    cn = new fyiReporting.Data.iTunesConnection(cstring);
                    break;
            #if EnableBundleLinux
                    // See properties -> Build -> Conditional compilation symbols
                case "sqlite":
                    cn = new Mono.Data.Sqlite.SqliteConnection(cstring);
                    break;
                case "postgresql":
                    cn = new Npgsql.NpgsqlConnection(cstring);
                    break;
            #endif
                default:
                    if (SqlEntries == null){         // if never initialized; we should init
                        RdlEngineConfigInit();
                }

                System.Console.WriteLine("Attempt to find provider");
                    SqlConfigEntry sce = SqlEntries[provider] as SqlConfigEntry;
                    if (sce == null || sce.CodeModule == null)
                    {
                        if (sce != null && sce.ErrorMsg != null){   // error during initialization??
                            throw new Exception(sce.ErrorMsg);
                    }
                        break;
                    }
                System.Console.WriteLine("Provider Create Instance");
                    object[] args = new object[] { cstring };
                    Assembly asm = sce.CodeModule;
                    object o = asm.CreateInstance(sce.ClassName, false,
                       BindingFlags.CreateInstance, null, args, null, null);
                    if (o == null)
                        throw new Exception(string.Format(Strings.RdlEngineConfig_Error_UnableCreateInstance, sce.ClassName, provider));
                    cn = o as IDbConnection;
                    break;
            }

            return cn;
        }
        public static IDbConnection GetConnection(string provider, string cstring)
        {
            IDbConnection cn = null;
            switch (provider.ToLower())
            {
                case "sql":
                    // can't connect unless information provided; 
                    //   when user wants to set the connection programmatically this they should do this 
                    if (cstring.Length > 0)
                        cn = new SqlConnection(cstring);
                    break;
			    case "filedirectory":
    				cn = new fyiReporting.Data.FileDirConnection(cstring);
    				break;
                case "xml":
                    cn = new fyiReporting.Data.XmlConnection(cstring);
                    break;
                case "webservice":
                    cn = new fyiReporting.Data.WebServiceConnection(cstring);
                    break;
                case "weblog":
                    cn = new fyiReporting.Data.LogConnection(cstring);
                    break;
                case "text":
                    cn = new fyiReporting.Data.TxtConnection(cstring);
                    break;
                case "itunes":
                    cn = new fyiReporting.Data.iTunesConnection(cstring);
                    break;
                default:
                    if (SqlEntries == null){         // if never initialized; we should init 
                        RdlEngineConfigInit();
				}
				System.Console.WriteLine("Attempt to find provider");
                    SqlConfigEntry sce = SqlEntries[provider] as SqlConfigEntry;
                    if (sce == null || sce.CodeModule == null)
                    {
                        if (sce != null && sce.ErrorMsg != null){   // error during initialization?? 
                            throw new Exception(sce.ErrorMsg);
					}
                        break;
                    }
				System.Console.WriteLine("Provider Create Instance");
                    object[] args = new object[] { cstring };
                    Assembly asm = sce.CodeModule;
                    object o = asm.CreateInstance(sce.ClassName, false,
                       BindingFlags.CreateInstance, null, args, null, null);
                    if (o == null)
                        throw new Exception(string.Format("Unable to create instance of '{0}' for provider '{1}'", sce.ClassName, provider));
                    cn = o as IDbConnection;
                    break;
            }

            return cn;
        }