Windows Workflow - Web Service - App_Data Directory - Database
-
05-07-2019 - |
Question
Solution
-- WorkflowProject
-- Workflow1
-- Workflow2
-- WebProject (WAP)
-- App_Data
-- MyDatabase.vdb3
-- MyWebService.asmx
-- Web.Config
Ok, so.. that's the basic "outline" of the project. The database, is stored in the website, and is a VistaDB database (this could also be an MSAccess or SQLite Database). In the website, I could code against the database. I might have |DataDirectory| in my connection string.
The WORKFLOW project is separate from the Website. The MyWebService.asmx is a "stub" for calling the Workflow based web service.
How do I open the database in the website App_Data directory ? Right now, I have the value hardcoded (i.e., @"E:\datadirectory\database.vdb3"), but this is not preferred and would only work on my development machine.
I can't even pass in the location of the database, since the webservice (the .asmx file) is only 1 line, and is stub code for getting the caller into the workflow. I'm really at a loss as how to proceed.
Solution ? Best practices ? Links ?
Solution 2
I wasn't able to get VirtualPathUtility to work. Here's the solution that I ended up finding that worked:
string s = AppDomain.CurrentDomain.GetData("DataDirectory") as string;
That gets the absolute path to the App_Data directory.
OTHER TIPS
You should take a look at "VirtualPathUtility"
substitute the result of:
VirtualPathUtility.ToAbsolute("~/App_Data/db.vdb3");
into your connection string.