我需要从控制台应用程序中的 asp.net mvc 3 应用程序获取用户 ID。这是我的代码:(mvc)
public class MembershipRepository : IMembershipRepository
{
public Guid GetUserId(string name)
{
var providerUserKey = Membership.GetUser(name).ProviderUserKey; // HttpException
if (providerUserKey != null)
return (Guid)providerUserKey;
throw new NullReferenceException("user with this username does't exist");
}
}
(控制台)代码:
ninjectKernel.Bind<IMembershipRepository>().To<MembershipRepository>();
var membershipRepository = ninjectKernel.Get<IMembershipRepository>();
Guid userId = membershipRepository.GetUserId("admin");
HttpException:无法连接到 Sql 服务器数据库。
异常发生前弹出窗口:此程序存在兼容性问题(microsoft sql seqver 2008 和 2008 r2)。
我已经安装了 sql server 2012。
此外,它只是一小段代码。在我尝试获取 userId 之前,我使用其他存储库将数据添加到数据库并且它可以工作:当我检查表内容时,它充满了新条目。
我需要如何更改代码?Mabby 还有其他方法可以在控制台应用程序中获取 userId 吗?
谢谢!
编辑:
App.config 文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add
name="WebStoreConnectionString" connectionString="Data Source=(LocalDB)\v11.0; DataBase=WebStore;
AttachDbFilename=C:\Users\Aleksey\repos\working_copy\WebStore\WebStore\App_Data\WebStore.mdf;
Integrated Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
</configuration>