我使用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