问题描述
我的项目是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
所以,这不是完全错误,但现在可以。