获取位于另一个DLL中的.mdf文件的连接字符串 [英] Get connection string to .mdf file that is located in another DLL

查看:81
本文介绍了获取位于另一个DLL中的.mdf文件的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi, i have encoutered following problem.
I have asp.net application named "Blog" and DLL with database named "DataAccess". DataAccess is referenced to Blog.
The Connection String that works and is located in Blog looks like:

     <connectionStrings>
    <add name="BlogDatabase" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\THERE\IS\FULL\PATH\Projects\BloggProject\DataAccess\App_Data\BlogDatabase.mdf;Integrated Security=True;Connect Timeout=30"/>
  </connectionStrings>

but what i want is something like this:

    AttachDbFilename=~\DataAccess\App_Data\BlogDatabase.mdf

where DataAccess is my DLL folder, i mean i want a connection string that is located in my asp.net application that points to this dll not only on my PC.





提前致谢。

Bartek。



Thanks in advance.
Bartek.

推荐答案

1.表示不将数据访问层与用户界面层混合,因此您应将所有数据访问代码和关联的数据库文件保存在单独的程序集(DLL)中。



如果你想从你的UI访问数据库,你应该通过调用数据访问层中的方法间接地进行数据库。



2.Better不是从子订单访问您的数据库文件(.mdf文件),而是使用指向SQL Server位置的连接字符串,如: Server = myServerAddress; Database = myDataBase; Trusted_Connection = True ;



这样,如果您还需要从您的Web应用程序直接访问某些数据来自数据库你可以使用相同的连接字符串(通过你的web.config文件),但更好的是使用图层!
1.It is indicated to not mix Data Access Layer with User Interface Layer, so you should keep all data access code and associated database file in separate assembly (DLL).

If you want to access the database from your UI you should do it indirectly by invoking methods from your Data Access Layer.

2.Better is to access your database file (.mdf file) not from a suborder, but using a connection string that point to a SQL Server location like: "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;"

In this way if you will need also from your web application to access directly some data from the database you will could use the same connection string (via your web.config file), but better is to use layers!


这篇关于获取位于另一个DLL中的.mdf文件的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆