How can I connect my SQL Server database that is placed on another server using API or Web Service in MVC to website that is on a different server - sql-server

I uploaded my website to GoDaddy web hosting and the database is placed on another server.
I want to create an API - either REST or SOAP - to connect my web site with my SQL Server database.
I need help - how can I create an API in ASP.NET MVC 5 so that I can connect my database with my web site? Kindly provide me with a link or code so that I can solve my issue.
I have never worked on API before - any help will be much appreciated.

ASP.NET MVC is now old school. Try ASP.NET Core.
You need to design and develop an N-Layered application: Data, Service and UI.
It doesn't matter where the database server is sitting, as long as your WebAPI can connect to it.
I suggest you build a restful web api with asp.net core :
https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio
Put your db connection string in the app settings file.

Although you use other database server, it doesn't matter. You just need to make sure you check your connection string and point it to your database server. For publishing method, it is same, you can use FTP or Visual Studio
Please open your project with Visual Studio tool
On the Solution Explorer windows (which is normally located on the top right hand corner of the VS tool), right click your project and select Publish
Please kindly publish it to a local folder, such as C:\Project
Please just upload whatever files/folders you see on C:\Project to your server via FTP
If you have any problems, you can contact your support team

You can get the Reference from
Sample_WebAPI_Project ,
instead of Using List created you can create Database Connection and get data from Database

Related

Creating ASP.NET MVC Core app on Mac OSx with MS SQL Server db on Azure

I'd like to know whether anyone has successfully created ASP.NET MVC Core App with Azure hosted SQL Server as backend?
I'm trying to follow/mix up following tutorial.
https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-webapp-using-vs
I created MVC app using yeo generator, it is running fine locally including Register link on landing page.
I deployed to Azure using local git, it runs upto displaying landing page, when I submit signup page I get error. Locally it's using SQLite .db file which I want to change to MS SQL Server db created on Azure. I put correct connection for this Azure SQL Server db in application settings and ran app from Azure link but got error.
Has anyone tried similar approach? I'm stuck here, any help is appreciated.

Visual Studio web and SQL publish

Here's the scenario:
MVC web project
Three MS SQL Server database projects
One of the databases must be populated with lookup tables
Other tables are user data and don't need data uploading
GoDaddy hosting
Visual Studio 2013
I'd like to deploy everything (web project, sql schemas, reference data) to GoDaddy in one fell swoop, but they appear to only offer FTP uploading. When using FTP in the Web Publishing Wizard, it says "Database preview not supported for this method" which I'm taking "method" to mean FTP. I can publish the web project fine in FTP, but of course without the databases the web application generates errors.
So here are my questions
There is a "Web Deploy" publish method listed in the wizard, but GoDaddy has no information on how to set this up. Can this be used with GoDaddy and will it publish DBs also?
How does one configure the project to use the local SQL Server when running on localhost, but when deployed it uses the GoDaddy SQL Servers?
Can the data in the local DB be uploaded as part of the publishing wizard process, or is SQL Server Management Studio the tool of choice?
Thanks!
I don't believe GoDaddy supports WebDeploy. They didn't when I left their service a few years ago. You can talk to them to confirm whether this has changed.
This is the role of Web.Config Transforms. For an intro to the topic, see here; the article is a little out of date and doesn't mention one of the most useful points - you can add transforms for each publish profile, so they're applied according to your publish settings.
You probably can't upload the local DB file. In almost every hosting situation, the SQL server and the web server are two separate machines, and don't share any files (corollary: the web server doesn't have the SQL service installed). One workaround you can try is to publish the DB directly from your own machine. That is, if you can connect to the DB from your machine, you can do a Web Deploy publish to your own machine but it will send the SQL changes to your GoDaddy DB server.
A more advanced workaround for #3:
Set up your FTP publishing settings for your files
Figure out how to publish your DB through WebDeploy only/from the command line (you can refer to here for a sample using WebDeploy from the command line; note this is going from GoDaddy -> Local, but it's trivial to turn it around)
Customize the web publish pipeline to insert an MSBuild target to execute your WebDeploy command line (see here for an example of modifying the pipeline; you can add the target directly in your .pubxml file if you're not intending to use it for multiple projects).
This will give you a single publish profile which will separately publish your files (via FTP) and your DB (via WebDeploy).

How to Successfully Deploy a Lightswitch 2013 HTML App to Azure with a Linked SQL Server database?

I've created a Lightswitch HTML application in VS 2013. It relies on a SQL Server database which was created locally and then uploaded to Azure. The database was then linked to the Azure web site.
I tested my database connection strings in the publish routine and they succeeded. The publish succeeded, but when I browse my azure URL, I receive the following message:
You do not have permission to view this directory or page.
What must be done to remedy this error?
I had a similar problem that would not resolve until I moved to a "Pay-As-You-Go" subscription rather than a "Free Trial".
I also had the same problem, but did NOT have to move to a "Pay-As-You-Go" subscription to get it working. Here was what I had to do.
The Azure management portal will tell you that the Site URL is something like https://mywebsite.azurewebsites.net/
but to test a Lightswitch HTML5 client application, the URL in Azure will actually be https://mywebsite.azurewebsites.net/HTMLClient/
Hope that helps.

How can I Upload my ASP.NET website(with database)?

this is my first project ^_^
and I have no previous experience.
I did create the database in my project from within the MVC.
Add New Item > SQL Server Database
then I use ADO.NET Entity DataModel
and I don't need to open my connection each time I deal with the database.. it's only the connection string in the Web.config..
my question is :
how can I upload my database?
is there any resource for such beginner as me :$ ?
I did Google it but I found it very hard for me to know if this is what I want or not, that's why I came here :$
It really depends on what type of access you have to your server.
If you have remote desktop access then run remote desktop (mstsc in run) and connect to your server.
This article shows how to install your web application in IIS on server.
This blog post from Scott Guthrie shows you how to deploy your sql database to your server.
In case you only have access to your server via a control panel (plesk) you should still be able to do the same via a different interface. (you need to go through the instructions given for the specific control panel you are using).
Hope this helps.
For ASP.Net website, just upload all files using FTP, in wwwroot folder of your hosting.
For SQL Server database there are following option.
Attach your MDF file on hosting database server (if you have remote desktop).
Generate a script of whole database with full data, schema, and indexes etc. and run the script in query editor of your hosting panel.
First of all create a database from your hosting panel and a user for your database then Use SQL Serer 2008 (R2 most preferable) and connect with your hosting SQL Server using hosting server name in Server name, your db user id in User Name, and same for password. And then connect, you will find a long list of databases including your own database. Now right click on your database and import data from your local database server to remote database server.

Silverlight SQL 2005

I want to allow a user to provide their SQL login credentials, and display local SQL tables, stored procs, etc. in a listing. Is this possible? Note: I do not want to install some local, small SQL variant. I'm talking about the full version of SQL 2005+ that's already sitting on a developer's workstation.
Silverlight provides no mechanism for connecting to a SQL Database directly. You either need to provide a set of web services to interface with your data source or use ADO.NET Data services.
Connecting to a local SQL database using Silverlight alone isn't possible.
Something I almost missed is that you don't want to connect back to a database on the web server. You want information about a possible sql server instance on the user's (developer's) local machine. That isn't possible from within Silverlight alone.
I had thought you might be able to send the credentials on to the web server, have it dynamically generate a connection string, and then use the information_schema views to return lists of tables and views like any other data source. But that won't work.
However, in that scenario the web server is essentially acting as a proxy for your silverlight app. You might be able to build something else to act a proxy instead. Perhaps a small clickonce winforms app. That would install from a web page via hyperlink, so you could craft a link to install it on the page hosting your silverlight app.
With silverlight you cannot access the local machine/network resources. you will need to use wpf/xbap.

Resources