Dynamic Data to external database asp.net - asp.net

I'm stepping through a walk through which allows me to create a dynamic data website.
Though in all the tutorials, including the one above, they all point to a local file based database. I need to add an external data model.
How could I add an external data model to the project? (A database hosted on a seperate SQL Server)
I've tried connecting through the SQL Server Object Explorer then dragging it into App_Data, but that didn't work.

Use the connection string in the web.config, but as you add the EF data model you should be given the opportunity to select you database by browsing for it.

Related

Copy some entries from one server database to other server database using asp.net mvc

We are doing some CRUD operation in DEV environment and data is saved in database. For other environments(like Staging/Prod) we want to copy those records from DEV database and paste to Staging/Prod when required using asp.net MVC. Is it possible? Could you please suggest some pathway in order to accomplish this?
You can accomplish this using a linked server:
https://learn.microsoft.com/en-us/sql/relational-databases/linked-servers/create-linked-servers-sql-server-database-engine?view=sql-server-ver15
This involves creating a link between one database server and another (they must be able to see each other on the network). You can then reference the linked server like this:
INSERT INTO [LinkedServerName].[Database].[dbo].[Table] (......
Alternatively you could use a paid for tool like SSMS tools which can generate insert statements on a per table basis: https://www.ssmstoolspack.com/

Is it possible to store a pseudo SQL Server database for my ASP .NET project?

My ASP.NET project is using SQL Server as the database. I am wondering if it is possible to store a temporary instance of my database so that I would only need to query once to work with the data that I need. For example, I will query the 2 tables, Person and Students with a common id. I want to be able to join the tables and use the information.
I think there are some solutions:
Store the tables in the front end and use ajax javascript to manipulate the tables information.
Store in a txt file or similar file on to the project folder as a pseudo database.
Would love to hear any ideas!
You could do worse than consider SQL Server Compact edition:
https://www.microsoft.com/en-za/download/details.aspx?id=17876
Which has a small footprint and supports private deployment of its binaries within the application folder
EDIT:
It seems CE is deprecated since last I used it. and MS now recommend SQL Server Express Local DB
https://learn.microsoft.com/en-gb/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-2017
And there is also SQLLite: https://www.supinfo.com/articles/single/6941-an-aspnet-core-mvc-app-with-sqlite-and-entity-framework

Storing and retrieving images in sql server 2005 in asp.net via c#

How do I store and retrieve images in sql server 2005 in asp.net with c#
You may store them as binary data.
You may write a module (derived from IHttpModule), register it for RequestBegin event.
When request come you may retrieve data from database, store it on disk with requested file name and
this image will automatically be returned by built-in IIS handler (which is written in native code and works very fast).
Here is a project that does just the thing. All you need to do is move the storing and retrieving logic into your ASP .Net application.
It is not recommended.
Best practice is storing meta-data (here meta-data is you image file name) inside database and sotre them on file-system (for example c:\images). Then when you need an image you can ask database for its name and retreive it from file-system.
This helps you to have a compact database and maintenance became easy. Handling large databases backup/restore is a headache.

linq to entities 3.5 across multiple databases in same engine

What do i need to do in order to be able to query across multiple databases which are in the same db engine?
I have added the .edmx file of 1 database, but i only need 1 view from another db.
Thanks in advance!
Here are a couple of options:
Depending on your database platform, make the view from your second database available in your first database. If you're using SQL Server, you can use a linked server. If you're using Oracle, you can use a DB Link. Simply create a view in your main database where the view's select statement utilizes the linked server or db link to reference the view from your second db.
Create a second .edmx file for your second database. This is the route I chose recently. However I was dealing with one SQL Server DB and one was Oracle DB. There were also multiple tables and functions from both being used. I determined that it was cleaner in my case to create two separate data access projects, one for each DB, each with it's own .edmx.
Hope this helps.

How to create a database and populate it during setup

I would like to find a way to create and populate a database during asp.net setup.
So, what I'm willing to do is:
Create the database during the setup
Populate the database with some initial data (country codes or something like that)
Create the appropriate connection string in the configuration file
I'm using .NET 3.5 and Visual Studio 2005, and the Database is SQL Server 2005.
Thanks in advance.
If you are creating an installer I'm sure there is a way to do it in there, but I am not all that familiar with that.
Otherwise, what you might do is the following.
Add a application_start handler in the Global.asax, check for valid connection string, if it doesn't exist, continue to step two.
Login to the server using a default connection string
Execute the needed scripts to create the database and objects needed.
Update the web.config with the connection information
The key here is determining what the "default" connection string is. Possibly a second configuration value.
Generally, you'll need to have SQL scripts to do this. I tend to do this anyway, as it makes maintaining and versioning the database much easier in the long run.
The core idea is, upon running the setup program, you'll have a custom action to execute this script. The user executing your setup will need permissions to:
Create a database
Create tables and other database-level objects in the newly-created database
Populate data
Your scripts will take care of all of that, though. You'll have a CREATE DATABASE command, the appropriate CREATE SCHEMA, CREATE TABLE, CREATE VIEW, etc. commands, and then after the schema is built, the appropriate INSERT statements to populate the data.
I normally break this into multiple scripts, but YMMV:
Create schema script
"Common scripts" (one for the equivalent of aspnet_regsql for web projects, one with the creation of the Enterprise Library logging tables and procs)
Create stored procedure script, if necessary (to be executed after the schema's created)
Populate initial data script
For future maintenance, I create upgrade scripts where a single script typically handles the entire upgrade process.
When writing the scripts, be sure to use the appropriate safety checks (IF EXISTS, etc) before creating objects. And I tend to make mine transactional, as well.
Good luck!
Well, actually I found a tutorial on MSDN: Walkthrough: Using a Custom Action to Create a Database at Installation
I'll use that and see how it goes, thanks for your help guys, I'll let you know how it goes.
If you can use Linq to Sql then this is easy.
Just import your entire database into the Linq to Sql designer. This will create objects that describe all objects in your database, including the System.Data.Linq.DataContext derived class that encapsulate the entire database setup.
Now you can call DataContext.CreateDatabase() to create the database.
See here more information.

Resources