微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用TopShelf的Windows服务:基础提供程序在打开时失败用户登录失败

如何解决使用TopShelf的Windows服务:基础提供程序在打开时失败用户登录失败

我的项目是TopShelf创建的窗口服务。它将数据存储在本地数据库中,但发生错误

System.Data.Entity.Core.EntityException:基础提供程序在打开时失败。 > System.Data.sqlClient.sqlException:用户登录失败“ USER”

我的字符串连接是:

  <connectionStrings>
    <add name="ValeQpsContext" connectionString="Data Source=.\sqlEXPRESS01;Initial Catalog=Vale.Qps;Integrated Security=False;
         User Id=USER; Password=xxxx" 
         providerName="System.Data.sqlClient" />
  </connectionStrings>

我的数据库是使用sql EXPRESS的本地数据库,我的服务作为本地系统运行。

这是在数据库中存储数据的方法

public static void Insert<T>(T entity)
            where T : class
        {
            try
            {
                using (var ctx = new MyContext())
                {
                    ctx.Entry(entity).State = System.Data.Entity.EntityState.Added;

                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

这是一个完整的内部异常:

基础提供程序在打开时失败。 System.Data.Entity.Core.EntityException:基础提供程序在打开时失败。 > System.Data.sqlClient.sqlException:用户登录失败“ USER”。 System.Data.ProviderBase.DbConnectionPool.TryGetConnection em.System.Data.ProviderBase.DbConnectionPool.TryGetConnection em System.Data.ProviderBase.DbConnectionFactory.TryGetConnection em System.Data.sqlClient.sqlConnection.TryOpenInner em System.Data.sqlClient.sqlConnection.TryOpen em System.Data.sqlClient.sqlConnection.Open em System.Data.Entity.Infrastructure.Interception.DbConnectiondispatcher。 c.b__13_0 em System Data.Entity.Infrastructure.Interception.Internaldispatcher`1.dispatch System.Data.Entity.Infrastructure.Interception.DbConnectiondispatcher.Open em System.Data.Entity.Core.EntityClient.EntityConnection.b__55_0 em System.Data.Entity.sqlServer .DefaultsqlExecutionStrategy。 c__displayClass2_0.b__0 em System.Data.Entity.sqlServer.DefaultsqlExecutionStrategy.Execute em System.Data.Entity.sqlServer.DefaultsqlExecutionStrategy.Execut e System.Data.Entity.Core.EntityClient.EntityConnection.Open

在SSMS中为数据库定义了相同的权限(用户和密码)。错误在哪里?

解决方法

我找到了解决方案。我将连接字符串更改为:

Partition

我还更改了命令以安装服务。添加了登录用户:

ParDo

所以,这不是完全错误,但现在可以。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。