Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid object name 'Hangfire.Job'. #1479

Closed
afresh opened this issue Aug 1, 2019 · 3 comments
Closed

Invalid object name 'Hangfire.Job'. #1479

afresh opened this issue Aug 1, 2019 · 3 comments

Comments

@afresh
Copy link

afresh commented Aug 1, 2019

It's running successfully in my VS debug, and in iis release. But the codes that my other team members pulled from TFS cannot run successfully. They catch the exception "Invalid object name 'Hangfire.Job'" at "BackgroundJob.Enqueue()".
I find their sqlserver has no tables about Hangfire. But the ConnectionString(DBCommon.ConnectionString) is right. Now, the code runs successfully only in my computer. How to solve this problem, please?

        private IEnumerable<IDisposable> GetHangfireServers()
        {
            GlobalConfiguration.Configuration
                .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                .UseSimpleAssemblyNameTypeSerializer()
                .UseRecommendedSerializerSettings()
                .UseSqlServerStorage(DBCommon.ConnectionString, new SqlServerStorageOptions
                {
                    CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                    SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                    QueuePollInterval = TimeSpan.Zero,
                    UseRecommendedIsolationLevel = true,
                    UsePageLocksOnDequeue = true,
                    DisableGlobalLocks = true
                });

            yield return new BackgroundJobServer();
        }

        public void Configuration(IAppBuilder app)
        {
            // 有关如何配置应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkID=316888

            XmlConfigurator.Configure();
            
            // Hangfire
            try
            {
                app.UseHangfireAspNet(GetHangfireServers);
                app.UseHangfireDashboard();
                BackgroundJob.Enqueue(() => Debug.WriteLine("Easy Hangfire!"));
                RecurringJob.AddOrUpdate("create-timing-wxpush-task", () => WxPushTask.CreateTimingWxPushTask(), Cron.Minutely);
            }
            catch (Exception)
            {
                //ignore
            }
        }

Enviroment:
1.vs2015
2.dotnet 4.5.2
3.windows 10
4.sql server 2008 r2/sql server 2012

@nmg196
Copy link

nmg196 commented Oct 19, 2021

I have the same issue.

@dmumladze
Copy link

@nmg196 @afresh - You need to add PrepareSchemaIfNecessary = true

GlobalConfiguration.Configuration.UseSqlServerStorage(DBCommon.ConnectionString, new SqlServerStorageOptions
{
    ...             
    PrepareSchemaIfNecessary = true
});

@afresh
Copy link
Author

afresh commented Feb 8, 2022

@dmumladze Thanks!

@afresh afresh closed this as completed Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants