【发布时间】:2012-01-30 04:32:53
【问题描述】:
我有一个 Access VBA 项目,我从中引用了一个用 C# 编写的 COM Interop .TLB。此 C# 代码仅查询 SQL Server 数据库并通过简单的 LINQ-to-Entity 查询返回值。
我遇到了这个问题中提到的相同错误:
但是,就我而言,它是 .ADP 应用程序中的 Access VBA,它引用我的 .Net 4.0 TLB,而不是另一个 .Net 项目。
我知道,如果它是另一个 .Net 项目,我可以在其 app.config 或 web.config 中添加 EF 连接字符串 XML。但是,如果我的“调用”应用程序是 Access 2003 VBA,解决方法是什么?
这是调用 .Net 代码的 VBA 代码
Dim CandidatePassword As String
Dim abc As New MISHash.Password
Dim PasswordStatus As Boolean
CandidatePassword = InputBox("Enter your password")
PasswordStatus = abc.IsValidPassword("myusername", CandidatePassword) ' FAILS HERE
If PasswordStatus Then
MsgBox "Password valid."
Else
MsgBox "Password failed."
End If
请帮忙。谢谢你。
更新:这是我的 C# 代码
using System.Linq;
using System.Runtime.InteropServices;
namespace MISHash
{
public class Password
{
public Password()
{
}
[ComVisible(true)]
public void HashAndSave(string SomePassword)
{
string hashed = BCrypt.HashPassword(SomePassword, BCrypt.GenerateSalt(12));
//save the hashed password in the database
}
[ComVisible(true)]
public bool IsValidPassword(string CandidateUserName, string CandidatePassword)
{
string OriginalHashedPassword;
using (MyDBEntities mycontext = new MyDBEntities())
{
OriginalHashedPassword = (from usr in mycontext.Users
where usr.UserName.Equals(CandidateUserName)
select usr.Password).FirstOrDefault();
}
bool matches = BCrypt.CheckPassword(CandidatePassword, OriginalHashedPassword);
return matches;
}
}
}
【问题讨论】:
标签: vba com .net-4.0 entity-framework-4 com-interop