NOSQL (RavenDB) Query from a folder on C: Drive - c#

I have a database on the C drive and I need to query from it to get all of the names of restaurants. I'm new to RavenDB and can't seem to find any documentation on how to query from a folder that sits on the C drive of the computer. Does anyone have any idea on how to do this?

If the database was created in drive C at creation time, then RavenDB knows where it is located.
Run your RavenDB server.
Specify your localhost URL when initializing the store:
var store = new DocumentStore
{
Urls = new[] {"http://127.0.0.1:8080"},
Database = "your-database-name"
};
store.Initialize();
After that, you just query your database.
If you manually moved the database from its original created location to some other folder then you couldn't query.
You can Export the database and Import it to a new database in a new location.

You can point RavenDB server to a specific data directory - in this way you can load your database and query it.
Simply edit settings.json in the folder where you find Raven.Server.exe and write the desired data folder in DataDir property. In the end, your settings file would look similar to this:
{
"DataDir": "D:\\foo\\bar",
/* other settings... */
}
Note, if you run RavenDB in Docker, you can adjust the configuration using environment variables. (more about this here: https://ravendb.net/docs/article-page/4.2/csharp/start/installation/running-in-docker-container)

Related

Azure Data Lake: How to get Processed files

I've just started working with Data Lake and I'm currently trying to figure out the real workflow steps and how to automatize the whole process.
Say I have some files as an input and I would like to process them and download output files in order to push into my data warehouse or/and SSAS.
I've found absolutely lovely API and it's all good but I can't find a way to get all the file names in a directory to get them downloaded further.
Please correct my thoughts regarding workflow. Is there another, more elegant way to automatically get all the processed data (outputs) into a storage (like conventional SQL Server, SSAS, data warehouse and etc)?
If you have a working solution based on Data Lake, please describe the workflow (from "raw" files to reports for end-users) with a few words.
here is my example of NET Core application
using Microsoft.Azure.DataLake.Store;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest.Azure.Authentication;
var creds = new ClientCredential(ApplicationId, Secret);
var clientCreds = ApplicationTokenProvider.LoginSilentAsync(Tenant, creds).GetAwaiter().GetResult();
var client = AdlsClient.CreateClient("myfirstdatalakeservice.azuredatalakestore.net", clientCreds);
var result = client.GetDirectoryEntry("/mynewfolder", UserGroupRepresentation.ObjectID);
Say I have some files as an input and I would like to process them and download output files in order to push into my data warehouse or/and SSAS.
If you want to download the files from the folder in the azure datalake to the local path, you could use the following code to do that.
client.BulkDownload("/mynewfolder", #"D:\Tom\xx"); //local path
But based on my understanding, you could use the azure datafactory to push your data from datalake store to azure storage blob or azure file storge.

how to save data in shared database file in C#

I use mdf database file. In server side I keep mdf file in D drive. Now I share this mdf file via lan to client system. If Client add any data means, it want to save in this shared .mdf file. For this how can I Proceed this and what is the connection string for this. Please reply me as soon as possible.
Thank You
By adding "|DataDirectory|" to your DataSource, you can make the path relative to the execution directory, so the user doesn't have to put a new path inside the DataSource. As far as I know you can't access the data from your customer. You would have to synchronize your DB with your customers.
Saving your data programmatically isn't that hard. Just use "SqlConnection", "SqlCommand"'s etc.
SqlConnection

how to create sqlite database in windows store app located at a specific folder

Need help, I can't seem to access any other .sqlite database if its not located in the apps localfolder. Every tutorial I look at they always use
Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Example.sqlite");
I tried this:
const string testing = #"C:\Users\***\AppData\Local\Packages\*************\LocalState";
this.DBPath = Path.Combine(testing, "Example.sqlite");
using (var db = new SQLite.SQLiteConnection(this.DBPath))
{
db.CreateTable<Customer>();
}
and it worked. but when I change it to:
const string testing = #"C:\Databases";
It can't open the database even if I copied the database from the local folder of the app.
Any suggestions ? I'm still trying to learn.
You can't access the C: drive for windows store apps. It's part of the store's sandbox. Each app is limited to which files and folders can be viewed. If you have a local database file you need to access, define the file as content in your app and access it using the path "ms-appx:///..."
use file picker to select which folder you want to save the db file.
refer this article:
http://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

How To Get Sql Database Backup File's Data and Log File Paths Using SMO in C#

I have found several posts about how to perform a database backup and database restore using the Sql SMO assemblies in C#. Basically if I want to make a copy of a database and give it a new name, I need to provide Relocate Files when doing the Restore. The Relocate Files consist of a Data File path and Log File path. If I'm restoring from an existing database then I can simply inspect the Database object's FileGroups property to get the Data File path, and it's LogFiles property to get the Log File path, then modify the path's filename to use the new database name, and provide these when doing the Restore. Without providing the Relocate Files the Restore operation would just overwrite the original database (overwrite it's .mdf (data) and .ldf (log) files).
So I have all that working fine, but now I've run into the case where I want to create a new database from a database backup file (.bak) that the user supplies, and they should be able to specify a new name for the database. In order to give the database a new name and not overwrite the existing database files (if they exist already), I need to know the backup file's Data and Log File paths.
Are there SMO functions that I can use to inspect a database backup file for it's database name, Data File path, and Log File path? I'm assuming there are, since SQL Management Studio is able to do it, but looking through the MSDN documentation I haven't come across it yet.
Thanks in advance.
== ANSWER ==
As linked to in Ben Thul's answer, the answer is to use the ReadFileList function on the Restore object. Here is some sample code:
Restore restore = new Restore();
restore.Devices.AddDevice(Path.GetFullPath(backupFileToRestoreFrom), DeviceType.File);
DataTable fileList = restore.ReadFileList(server);
string dataLogicalName = fileList.Rows[0][0].ToString();
string dataPhysicalName = fileList.Rows[0][1].ToString();
string logLogicalName = fileList.Rows[1][0].ToString();
string logPhysicalName = fileList.Rows[1][1].ToString();
Check this out: how to restore using restore class of Microsoft.SqlServer.Management.Smo namespace. In T-SQL, you'd accomplish this with restore filelistonly from disk='path_to_your_backup'

Restoring database to a new server with a new name

I am trying to create backup and restore of a database to new server with new name using C# and SQL server database. I can create a backup of the database but I am not able to restore it to the new server using the new name.
My query looks something like this: it doesn't work and errors out:
RESTORE DATABASE test1 FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\setupdb\BackupForsetupdb.bak'
WITH MOVE 'setupdb_Data' TO '\\newserver\e$\MSSQL\DATA\test1_Data.MDF',
MOVE 'setupdb_log' TO '\\newserver\e$\MSSQL\DATA\test1_Log.LDF';
I am trying to achieve this through C# code.It looks like the database cannot be restored to the remote servers. Please throw some light on this.
Thanks!
You can't have SQL Server databases on network shares normally: local/SAN type drives only
The backup file can be on a share but the MDF and LDFs must be local
There is an MS KB article on it: it can be done but at your own risk
Your paths for the move command have to be relative to the server.
e:\MSSQL\Data\test1_data.mdf
And your restore from path has to be relative to the server as well. If the c:\ is from your local machine, you either need to point it to a UNC path (\\yourpc\c$\...) or move it to the server. But be aware that if using the UNC path option, the user the server process is running as has to have permissions to access the share as well. So you're probably better off copying to a drive on the remote computer.

Categories

Resources