Using SQL Server databases on shared hosting - c#

I'm attempting to deploy an ASP.NET MVC 4.0 application, and I am using a shared web hosting solution. I am able to successfully deploy everything, except for my preexisting databases, one for user accounts, and one for posts.
These two databases are in the App_Data directory of my application.
Every part of the application requiring database communication returns the following:
Invalid value for key 'attachdbfilename'
I should note that this problem does NOT occur when testing locally.
My web hosting provider has created a SQL Server database, providing me with a server IP, a username/database name, and a password. However I'm unsure how I can access it, and then replicate the current database in my application in the database on my web host.
Basically my question is, how do I get my SQL Server databases to work on my web hosting?

In this scenario you should not attach your own DB files. Create a new database (e.g. using SSMS or host's Control Panel) on the server provided by the host. Import your local data into that DB and use new server/db/uid/password in your connection string.
If your host already provided you the DB - just use existing DB (don't create a new one) but still import your local data into that DB.

Related

Backup database with Entity Framework on ASP.Net

I have an interesting case. I lost access to an Azure subscription. However, I still have access to publishing an ASP.Net application, because I configured a publishing profile, which still works. Note, that this is nothing illegal - internal company policies regarding VS subscriptions; enough to say, that application is mine, written by me, maintained by me etc.
I need to create a backup of the database, but the only thing I can do is to publish the application. Application obviously have connection string embedded in settings, but I cannot connect to the database due to firewall settings (Azure services only). So I need to find a way to dump the data with a controller and action.
So far I managed to dump most tables manually (eg. var data = context.Table.ToList();) and then output results into view. However, this won't export internal ASP.Net tables, which I cannot access directly (eg. user/role claims etc.)
Keep in mind, that we're talking about Azure SQL, which differs from the regular SQL Server.
How can I back up the database, so that I can migrate application to a different subscription?
If you also can publish your webapp. You can create a API function and invoke it. Something like: https://yourwebsite.azurewebsites.net/backup/start.
You can create PROCEDURE, and run it to generate .bak file to blob(
The premise is that you need to know blob related information.).
Sample code like :
C# SQL Server backup of a remote database to the remote default backup location without direct access to the remote location?

Can't save data in SQL Server database, where to place the file?

In my application I need to use a local database (the application I'm creating works with everything locally). I had one database that worked really bad, because sometimes it saved the data and other times don't. And if I published the program I couldn't find the database file.
But I am having some trouble to know where to place the database. I have created one in E:\PAP\Trabalhos\Trabalhos\database.mdf and other in E:\PAP\Trabalhos\Trabalhos\bin\Debug\database.mdf, but in any of those paths the database is recreated/goes back to the previous state, when I try to start the program.
In my connection string I have this:
Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|database.mdf; Integrated Security=True
and that points to the file ...\bin\debug\database.mdf
I want to be able to access the database in any computer I use the program and be able to actually save data.
Where is the recommended path to place the database file and be able to access it independent of the computer I am using?
Should I use Windows authentication or SQL Server authentication?
tl/dr: Database doesn't save data and I want to be able to access it in any computer without any extra steps.
You can't use "(LocalDB)\" and access it from any computer. LocalDB is by design accessible only from the applications running on the same computer (it is an embedded database).
To access database over the network you need to install instance of SQL Server, like full SQL Server Express instance or use some cloud service like AWS or Azure.

Passing domain credentials to an ODBC connection attached to an access database using C# MVC 5 and IIS

I'm stuck with a problem where I am trying to query an access database that is located on our internal network using an ODBC connection to it. This works perfectly fine when running locally, but once you host the application onto IIS it no longer has access to the network folder that the database is stored in. Is there a way to use different credentials to access the folder other than the server's default?

Visual Studio 2012 move local .sdf file to server computer

here is the problem I am facing now. I have created an application that uses local database (this was created by Add -> New Item -> Local Database. Afterwards I have added tables under this .sdf database.
Then I have connected to this database using Add -> New Item -> ADO.NET Entity Data Model.
Everything works like a charm, unless I was asked to move this database to a place, where multiple people could access this database and work with it.
Therefore, as I have no previous experience with databases, I have treated this .sdf file as any other file (let's say Excel workbook) and I thought that I could simply take already existing database, copy it on server computer (e.g. \Server001\Database\Database1.sdf) and simply change connection string under app.config.
However the problem is that this does not work. As I didn't know how to change connection string, I created new application, where I have tried to connect to this database located on a server computer; however I received the following error:
SQL Server Compact does not support opening database files on a network share.
I already have fully functioning program, but I have no idea how to make it work with multiple users. I have tied to google for solution, but all I could find is how to create local database, not how to make it accessible by placing it in server computer.
Could you guys please help me? If you need more details, please let me know!
P.S. This is WPF application, .NET 4.5, created using Visual Studio 2012 Professional.
Thank you!
The error message pretty much sums up the problem: SQL Server Compact does not support opening database files on a network share.
SQL Server Compact (aka "local database") is to be consumed by a local application; even if it was a web app serving many requests, the application itself is local.
If you want to have multiple remote connections (i.e. centralized DB, distributed app), you should look at using an instance of SQL Server (any SKU would probably work, even SQL Server Express). Those will use MDF files instead of SDF files, so you might want to refer to Convert .sdf database to .mdf database. You'll probably also need to set up a user identity for your connection string, so check out this link on CREATE USER and Difference between a User and a Login in SQL Server to understand how that can be configured.

Share a SQL Server CE database in Azure Web and Worker roles

I'm trying to use a SQL Server CE database in Azure Web and Worker role and use it with EF. I have installed EntityFramework.SqlServerCompact (v4.3.6) and seems to work fine on the worker role. (which puts data in the database.)
Although when I try to read the data from my Web Role, it doesn't seem to recognize the database created by the worker role, and creates a new DB.
Database seems to be created by the worker role at \Debug\roles\WorkerRoleName\approot.
What is the best place to create the DB ? (Web role's App_Data ? or a blob storage location ?) and how do I configure EF so it looks in the same place no matter which role I ask the data from ?
If this is not possible with SQL Server CE, what other options do I have ? (don't want to use SQL Azure or table storage)
Thanks
I think you'll find SQL Server CE to not be viable for you, as it's a locally-installed database. I'm not sure if you've tested with multiple instances of your worker role, but you should find that these instances will not see each others' data (every instance is its own virtual machine). SQL Server CE is going to store its database file (the .sdf file?) in a local folder of the instance. Without some type of file-sharing set up, you won't be able to access this file from anywhere other than the instance it's installed on. And before you go exploring something like SMB, you should think about how SQL Server CE works, and if it would even support multiple database engines trying to read/write the same file.
I'm not sure why you want to avoid SQL Database (formerly known as SQL Azure), as it is db-as-a-service and may be accessed by all of your role instances, whether web or worker (or from anywhere else). Table Storage is something entirely different and not a SQL-based data store, so that makes sense.
One other option is to consider running SQL Server in a virtual machine, as SQL Server supports multiple clients just like SQL Database. There's a SQL Server image in the Virtual Machine gallery that you can use to spin up the database. You could then secure the connection from your cloud service to your SQL virtual machine either with a virtual network or an IP-ACL'd endpoint allowing only your cloud service's IP address to access it.

Categories

Resources