Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
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.


Thanks in advance.
Bartek.
Posted

1 solution

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!
 
Share this answer
 
Comments
Member 10409338 24-Jun-14 7:24am    
Ad. 1
I need this string to use DI, therefore it must be visible in UI where DI and controllerFactory are implemented.

Ad. 2
I can not use server for now because im developing this app on two seperate machines (home and work) and they have no mutual server. In this case i need atached .mdf file.
Raul Iloc 24-Jun-14 10:57am    
The connection string should be in the config files (web.config for UI and app.config for other cases) and you could add two configurations entries (one for home and the other for work) then to comment one of them and uncomment the second one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900