How to publish the MVC 5 Default Connection Database to winHost - c#

I have no experience with web hosting. This would be my first application to host.I have an MVC 5 application with Entity Framework. It is locally using two DBs, the one that I created (BailBond) and the default one named "aspnet-BailBondMS-20160913064154" because my project name is BailBondMS. When I publish it winhost, the default DB is not connected to the application. I manually tried to create a DB in my site database in winhost with the same name but it wont let me do it because the name is too long. I then shortened the name. The problem now is that I cannot update the default DB name in Visual Studio to match the one in my control panel in winhost.
What should I do? What am I doing wrong? Thank you for your help.

Related

Unable to Update Model from Database using EF 6 and Visual Studio 2015 Update 3

Right click on the EF Model Designer surface and choose Update Model from Database.
In the dialog box that pops up, you should be able to browse the database, and select objects to add. But in this case, nothing can be selected:
Removing the Connection String from the App.Config and allowing the Designer to re-add it did not resolve the issue.
The credentials used in the Connection String when copied and pasted in SSMS.
The database can be browsed from the VS Server Explorer window.
Creating a new blank EF project and repeating from there works fine.
What could be causing this?
One of 2 problems exist, the Model already has the Tables/SP/View you are looking for or the Login does not have the Authority the access those Tables/SP/View.
One of the factor unable to select any checkbox in Update Wizard is you don't have any updates in your database, therefore entity framework doesn't allow you to select.
If your scenario is not the factor above, you may try the method I listed below:
I had this issue too and I noticed that I didn't grant the db_owner under Database role membership for my database (eg 22Aug_M) in Microsoft SQL Server Management Studio.
After I checked it and it works as normal.

Visual Studio not creating edmx file using Entity Framework 6.1

Im trying to use Entity Framework on my .NET 4.0 Web Site. I already have installed Entity Framework 6.1 and i "Add New" ADO.NET Entity Data Model to my site using a valid connection string , and I select my table. I know this is a valid table with several columns and rows of data. After the creation is finished I am left with only a .cs file with no properties and a new connection string added to the web.config, but there is no .edmx file created. I know the SQL user in the Con String has read/write permissions and this is a valid table. Any clue as to what i may be doing wrong?
Have you tried to change the values of this new connection string with your values?
Take a look of this link and retry..
https://msdn.microsoft.com/en-us/data/jj206878.aspx
PS: I think that you should have created a "Project" and not a "new WebSite" using:
"Folder>New>Project> ASP Web App" in VS
Doing this you have all ready to go (references, EF etc..) then you could even start from a empty virgin model, or EF designer from database where you could easly manage or create entities, relations etc.

DNN Database Repository Reuse in Console Application

I have a project based on the Chris Hammond, Christoc, module template. I have a ton of code that I use to access data an external database. In my repositories I change the database from the default to whichever I need for that particular object. I do so with code that looks like this:
using (IDataContext ctx = DataContext.Instance(MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY))
{
var rep = ctx.GetRepository<Product>();
products = rep.Get().ToList();
}
The default database is switched in the call to .Instance(). The repositories are used by my custom DNN modules. The repository is part of the solution that contains multiple custom modules. When I compile and install using the Extensions part of DNN, everything works well. In the code above, MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY is found in a file MyModuleSettingsBase.cs file of my module solution. It is set to a simple string like "ProductDatabase". In the solution for the base DNN install (not the module solution), within the web.config file, there is a value in <connectionStrings> with name="ProductDatabase" which contains the actual connection string. This all links up fine on the DNN website.
Now I am writing a console application that does some monitoring of the site. I want to access the database to check values in the product table. I would like to reuse all of the repository code I have written. In an attempt to do so, I added a reference to the MyModules.dll file so I would only have one copy of the base code. This works to give me access to all the objects and the associated repositories but when I attempt to query data it fails. When debugging I can see that it fails on the line:
using (IDataContext ctx = DataContext.Instance(MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY))
When viewed in a debugger, the string value MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY is correctly set to "ProductDatabase" but the code is unable to link this with the actual connection string. I don't know where it would be checking for the connections string when running from my console application. I attempted to put a <connectionStrings> section into my App.config file but this didn't do the trick.
Is it possible to have MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY map to the connection string in an external application which references the DLL?
If so, where can I set the value of my connection string so it matches up to the key value stored in MyModuleSettingsBase.DATABASE_CONNECTION_STRING_KEY?
I was faced similar problem 3 months ago, at that time I want to use DNN core libraries in my console application but I was failed.
I placed my queries in DNN official forum website and I got a valid response from Wes Tatters (DNN MVP).
Here is the post link: Reference URL
As your requirement of monitoring, I suggest you to create DNN Schedule Application. You can schedule it within DNN (Host->AdvancedSettings->Schedule), even good point is that you can use your repositories (DNN Libraries) in that schedule application.
I hope it solved your problem. Let me know if you have any questions.

Adding Schema Name to SQL Table Names in ASP.NET Web Application

I am porting my SQL Server database to Azure SQL. The database has been replicated correctly and is now accessible from my existing web application.
However, the first time it was executed with the Azure SQL connection string, it showed "Invalid Object" for a table name used on the log in page.
I was able to correct it by adding the schema name [dbusername].[tablename] in place of [tablename] in the code.
Now since it is an extensive application, with over 300 ASPX pages and 30 tables, I'm wondering do I have to use the Find-Replace tool in Visual Studio or am I missing a setting that can help me to assign the default schema name while executing all queries ?
Set the default schema for your user.
USE MyDataBase;
GO
ALTER USER MyUser WITH DEFAULT_SCHEMA=MySchema;
GO
I believe this article will help you.
http://blog.sqlauthority.com/2008/12/26/sql-server-fix-error-msg-15151-level-16-state-1-line-2-cannot-alter-the-login-sa-because-it-does-not-exist-or-you-do-not-have-permission/

C# ASP.net MVC database questions

I am trying to develop a website with C# ASP.net MVC. It's my first time using Visual Studio, C# and ASP.net so I have lots to learn but so far so good.
So far... I started a C# ASP.net MVC project and added a database by going to the Database Explorer and clicking "add connection". I then did some standard CRUD controllers and views.
I am at the stage where I want to implement User authentication. I'm a bit confused here. I am trying to make a custom Membership Provider. So I added it to my web.config file with the correct connection string etc.
When I run the project and go to register I get an error. "Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'."
From searching, I see lots of people have this problem and they always reference their hosting. People say this (http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx) is their solution but when I try pick a database I get an error. Not even sure of my server name.
So at this point I am wondering, did I set up the database right?
EDIT
Adding in a few pics to show exactly what I am doing. This is the aspnet_regsql.exe:
This is the provider with connection string, taken from an example on one of the links given.
This is my customized provider with connection string pointing to the last image.
This is a screen cap when I run the project and go to the default project Account register action:
and finally, this is the error screen when I submit
EDIT
Another update..
I sorted something out but I am not sure if it is correct. I am now getting an error when the page loads: "Invalid object name 'dbo.Tag'"
In order to solve this problem the only thing you need to do is create an application services DB. You can achieve this by running the following command from your Visual Studio Command Prompt
aspnet_regsql
Anyways it seems that your "custom provider" isn't using a custom structure for your DB, which might be the reason why you weren't expecting this error.
If you are using the default implementation, you can access to the user administration using ASP .NET Configuration, located on your project menu in visual studio.
The default implementation uses the following conn string keyword
LocalSqlServer
The are many ways of implementing the membership provider. My guess is that probably this conn string is not pointing to your aspnet services db, you could do something like this to specify a custom location for this db
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnetdb.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
I made a blog post regarding this topic: How to use MembershipRole Provider and when to use custom implementations
It's hard to figure out anything from your post.
but when I try pick a database I get
an error.
You can check your server name in Surface area configuration or Sql Server Configuration Manager. If you installed Visual Studio it's probably YOUR_MACHINE_NAME\SQLEXPRESS. You can connect to it using Windows Authentication. You could also write localhost,1433 instead, but that would require enabling TCP/IP first(it's disabled by default) and setting the port number first(which in most cases is already set).

Categories

Resources