天道酬勤,学无止境

datadirectory

SQL Server Compact 'Data Directory' macro in Connection String - more info needed

Question So, as described on this msdn page, when you define a Connection String for SQL Server Compact 3.5, you can use the "Data Directory" macro, like this: quote from this msdn page: Data Directory Support SQL Server Compact 3.5 now supports the Data Directory macro. This means that if you add the string |DataDirectory| (enclosed in pipe symbols) to a file path, it will resolve to the path of the database. For example, consider the connection string: "Data Source= c:\program files\MyApp\Mydb.sdf" When using Data Directory, you can instead use the following connection string: "Data Source =

2022-05-05 12:27:23    分类:技术分享    .net   sql-server   sql-server-ce   connection-string   datadirectory

How to use |DataDirectory| substitution string in appsettings.json with asp.net core?

Question I'm new to asp.net core and the task I want to do should be very simple. Using Visual Studio, I'm trying to link a .mdf file to my project as a local database. As I want to make it work for several computers, I need to find the data directory folder path from appsettings.json. Therefore, after some researches, the best way to do that is using the |DataDirectory| substitution string. The problem is that my website can't reach my mdf file this way and it generates an ArgumentException : "Invalid value for key 'attachdbfilename'". Although I found some topics about this issue, none of

2022-02-12 11:17:16    分类:技术分享    c#   asp.net-mvc   asp.net-core   appsettings   datadirectory

Connection String to Connect to .MDF

Question I've created a new project in VS2008, and added a .MDF file to the project. This is the first time I've tried to use the MDF files and .SQLEXPRESS databases (I've always used extenal Oracle servers in the past). I'm trying to document everything as I go, but I can't figure out what credentials are being used to connect to the .MDF file. Is there an easy way to find out? Answer1 If you're using the *.mdf file in the App_Data folder of an ASP.NET app you can use this. Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes; If it's not an

2021-12-08 12:24:27    分类:技术分享    connection-string   sql-server-express   mdf   datadirectory

How to define DataDirectory for ConnectionString in console application to work with EntityFramework Code First Migrations

Question I try to set location MyProject\App_Data\Cos.mdf for the database in App.config: <connectionStrings> <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Cos.mdf;Initial Catalog=Cos;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /> </connectionStrings> In Program.cs I wrote: static void Main(string[] args) { string relative = @"..\..\App_Data\Cos.mdf"; string absolute = Path.GetFullPath(relative); AppDomain.CurrentDomain.SetData("DataDirectory", absolute); Console.WriteLine(absolute)

2021-06-21 10:13:48    分类:技术分享    c#   entity-framework   app-config   localdb   datadirectory

How do I read the current path of |DataDirectory| from config settings

Question I'm writing a program that requires the user to select the active database at application startup. I have a Windows Form that will list the databases stored in a sub-folder of ApplicationData specifically for storing the database files. When I create a new database, however, I need to copy the the template database, but can't figure out where it's stored by default. I've tried: dpath = ConfigurationManager.AppSettings["DataDirectory"]; I always seem to get a null value in return though. At one point I gave up and figured I could just set the DataDirectory to a folder of my choice, but

2021-04-03 18:57:10    分类:技术分享    c#   sql-server-ce   datadirectory

ADO.NET |DataDirectory| where is this documented?

Question In AppConfig it is possible to use |DataDirectory| but I can't find any doc ? Answer1 |DataDirectory| is a substitution string so you can configure the location of your database file separately. So instead of: SqlConnection c = new SqlConnection ( @"Data Source=.\SQLDB; AttachDbFilename=C:\MyDB\Database.mdf;Initial Catalog=Master"); you do the following: // Set |DataDirectory| value AppDomain.CurrentDomain.SetData("DataDirectory", "C:\myDB"); // SQL Connection String with |DataDirectory| substitution string SqlConnection c = new SqlConnection ( @"Data Source=.\SQLDB; AttachDbFilename=

2021-03-26 13:13:09    分类:技术分享    c#   ado.net   datadirectory