我使用System.Data.OracleClient。
System.Data.OracleClient需要OracleInstantClient,它們是本地dll的。 因此,爲了使用System.Data.OracleClient,我需要安裝本機dll,或者在路徑環境變量的文件夾中。
現在,基本的問題是,我沒有管理員權限(公司的筆記本電腦 - 企業的愚蠢 - 不會改變)...
因此,我既不能安裝任何東西,也不在PATH的文件夾中複製任何東西,我也不能將文件夾添加到PATH環境變量,我也可以重新啓動/管理IIS或任何其他服務......
那麼作爲一個測試,我只是複製OCI.DLL和oraociei11.dll到同一文件夾作爲WinForms .exe。
這工作得很好。我能夠毫無問題地訪問Oracle數據庫(SELECT * FROM COUNTRIES)。
但現在,我需要在ASP.NET解決方案中執行相同的查詢。 問題是,ASP.NET dll在執行時會將陰影複製到臨時文件夾。
我們得到的dll到Web應用斌非的少,
在Global.asax中的
public class MvcApplication : System.Web.HttpApplication
我重寫了初始化這個:
public override void Init()
{
int iBitNess = IntPtr.Size;
//System.Windows.Forms.MessageBox.Show(iBitNess.ToString());
// iBitNess = 4, so 32 bit dll's are right
string strTargetDirectory = System.Reflection.Assembly.GetExecutingAssembly().Location;
strTargetDirectory = typeof(DB.Abstraction.cDAL).Assembly.Location;
strTargetDirectory = typeof(MvcApplication).Assembly.Location;
strTargetDirectory = System.IO.Path.GetDirectoryName(strTargetDirectory);
string strSourcePath = Server.MapPath("~/bin/dependencies/InstantClient");
string[] astrAllFiles = System.IO.Directory.GetFiles(strSourcePath, "*.dll");
foreach (string strSourceFile in astrAllFiles)
{
string strTargetFile = System.IO.Path.GetFileName(strSourceFile);
strTargetFile = System.IO.Path.Combine(strTargetDirectory, strTargetFile);
System.IO.File.Copy(strSourceFile, strTargetFile);
}
base.Init();
} // End Sub Init
,以複製本地dll的到所謂的正確位置。 但我仍然得到DllNotFound異常...
我該在哪裏或如何將本機DLL放入ASP.NET應用程序?
我再說一遍:我無法設置環境變量,也無法將dll複製到路徑中的文件夾。(這通常會解決問題)。
在您使用的
strTargetDirectory =
我試了幾個possibilites,其中沒有工作的多次出現見。
所有你應該做的是把你的應用程序的bin文件夾中的DLL。你爲什麼要在Init()代碼中分別訪問DLL? – RickNZ 2012-01-07 09:08:55
@RickNZ:應該是對的。但事實並非如此。但我現在解決了它。新增解決方案 – 2012-01-07 09:39:55
@RickNZ:ShadowCopy將.NET dll複製到另一個文件夾中,並從那裏執行。因此,bin文件夾中的本機dll位於另一個文件夾中,並且不會找到/加載。 – 2015-05-20 10:01:39