0
我有一個Access VBA項目,我指的是使用C#編寫的COM Interop .TLB。此C#代碼只是查詢SQL Server數據庫並通過簡單的LINQ-to-Entity查詢返回值。訪問VBA中的實體框架錯誤 - 「在配置中找不到指定的命名連接...」
我得到這個問題提到了同樣的錯誤:
然而,於我而言,這是一個訪問VBA中引用我的.NET 4.0 TLB中的.ADP的應用,而不是另一個.Net項目。
我知道,如果它是另一個.Net項目,我可以在其app.config或web.config中添加EF連接字符串XML。但是,如果我的「調用」應用程序是Access 2003 VBA,那麼該修復程序是什麼?
這裏的VBA代碼調用的.Net代碼
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;
}
}
}
我的連接字符串看起來是這樣的:元= RES:// * /爲MyModel。 csdl | res://*/MyModel.ssdl | res://*/MyModel.msl; provider = System.Data.SqlClient; provider connection string =「Data Source = DBSERVER; Persist Security Info = True; User ID = dbuser ; Password = dbpwd; MultipleActiveResultSets = True;連接超時= 120;應用程序名稱= EntityFramework「我們如何將這個傳遞給構造函數? – FMFF 2012-01-02 19:55:57
我嘗試了在您的編輯下建議的方法;而不是連接字符串,我建立和使用EntityConnection連接對象建議[這裏](http://msdn.microsoft.com/en-us/library/bb738533.aspx),它的工作。非常感謝你給我指路。 – FMFF 2012-01-02 22:05:17