Uploading ASP.NET 3.5 website - c#

I have a website writen in ASP.NET and C#.
The site works when run locally, however I don't have any experience with uploading. Recently I got a free hosting package from somee.com and am currently trying to upload it.
Basically, the pages that don't require database connection work, the ones that do don't. So, I've created a database on somee.com and attached my database to that. I've tested it through somee.com control panel with a couple of querys and it works fine.
So I believe the site is uploaded correctly, database works also. I figure it must be a connection problem. In my codebehind, every database connection uses the web.config connection string. I believe there is a problem somewhere in the web.config file, specifically with the connection string.
I have replaced my connection string with the connection string generated by the somee.com control panel which is:
<add name="feniks_dbConnectionString"
connectionString="workstation id=SQLEXPRESS003.mssql.somee.com;packet size=4096;user id=*;pwd=*;data source=SQLEXPRESS003.mssql.somee.com;persist security info=False;initial catalog=SQLEXPRESS003"
providerName="System.Data.SqlClient" />
I've marked my id and pass with *. I keep getting the same error, you can try it yourself on http://aspsitetest.somee.com/index.aspx.

Error on page not about sql-connect - it writes about wrong web.config
search for duplicate:
There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined
If the same web.config works on local machine, maybe you use another version of IIS.

Related

What's the proper way to include Entity Framework connection string used in WCF service into a self hosting console application?

I'm doing my homework, a WCF service that uses SQL Server with Entity Framework, hosted through a console application, and using a WPF client.
There are 3 different projects, and the host and the service is in the same solution. I've included the Entity Framework connection string in the console hosts' app.config file from the web.config file from the service. This way the server and the host throw an exception when I try to make a query:
System.Data.Entity.Core.EntityException: 'The underlying provider failed on Open.'
The inner exception says:
SqlException: An attempt to attach an auto-named database for file C:\Users\username\source\repos\BlogAppWcf\BlogHost\bin\Debug\BlogDb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
So it basically searches for the .mdf file in it's own project folder, while it's inside the service's App_Data folder.
The original connection string looks like this, I copied this to the host's app.config from the web.config:
connectionString="metadata=res://*/BlogDbEntities.csdl|res://*/BlogDbEntities.ssdl|res://*/BlogDbEntities.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=(LocalDB)\MSSQLLocalDB;
attachdbfilename=|DataDirectory|\BlogDb.mdf;
integrated security=True;
MultipleActiveResultSets=True;App=EntityFramework""
I've tried modifying the AttachDbFilename attribute in the app.config, I gave it an absolute path like this:
attachdbfilename=C:\Users\username\source\repos\BlogAppWcf\BlogAppWcf\App_Data\BlogDb.mdf;
and this way it works like a charm! No more exceptions on queries.
But this isn't the right way to do it, especially because I have to send it to my teacher. I want to give it a relative path, just like this:
attachdbfilename=..\..\..\BlogAppWcf\App_Data\BlogDb.mdf;
but it doesn't work this way.
Has anyone got any suggestions, maybe I'm doing or thinking something completely wrong?
According to your description and the issue you encountered, I think the problem boils down to the fact that the attached database is not properly attached to VS built-in database server instance. For this reason, I think we could configure the EntityFramework with VS built-in database instance string.
Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MyStore;Integrated
Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
And then override the seed method of the DropCreateDatabaseAlways/DropCreateDatabaseIfModelChanges class to provide the seed data.
Feel free to let me know if there is anything I can help with.

How to change connexion string in a deployed Azure App

I have developed a website application under visual studio using the MVC Pattern and Entity Framework 6.
This web app was linked to a local database.
I've published the application on my azure acc. I also exported the database on Azure following this tutorial.
However, I can't find a way to link the online app to the migrated database.
No data is displayed on the app and when I try to check for the connexion string I get an error , the connexion string hasn't been updated and therefore the app is still trying to target my local database.
I would like to know if anyone might know how to solve this.
EDIT : The problem may be somewhere else, I apparently have two connexions , one for my migrated DB and one for my local db. Perhaps I need to remove the connexion string targetting my local DB but I don't know how to do that
Also, since the Migrated database is a copy from the local one I was using before, do I need to change anything in my Model,views or controller ?
EDIT2 : Thanks to the comment below I was able to override the false Connexion String. However my datas are still not displayed on my application and I haven't found yet what could have happend.
I suspect that my model is still the same model as the one used by the local database as it has the same name. Does anybody know how to change the model to the current model of the online database ?
Thanks.
Because you created your app with entity framework there should be a connection string defined in the web.config file pointing to the local database.
<connectionStrings>
<add name="MyContext" connectionString="..."
providerName="System.Data.SqlClient" />
</connectionStrings>
If you have published your Website as WebApp (App Service) then you can change the connection string for the database under the Application Settings pane on the WebApp Page.
You can override your connection string by creating a connection string settings entry with the name of the connection string in the web.config file.
(For the snippet above - MyContext)

Do you have to publish DefaultConnection containing the membership tables?

Attempting to publish a website to my host which contains my custom database and the default like so:
<add name="PortfolioContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Portfolio;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
When publishing the site I can't login which I assume is down to because the DefaultConnection db isn't being created (containing the membership user tables), I might be wrong? I can generate the script for my custom database in Management studio but DefaultConnection doesn't even appear to allow me to manually create tables associated.
My error log displays this
2016-02-02 12:28:35 W3SVC30 217.194.213.135 GET /Login
ReturnUrl=%2Fdashboard 80 - 95.147.124.217
Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/48.0.2564.97+Safari/537.36
- 500 0 0 1198 416 203
Though I'm not sure what that means. Sorry this is my first attempt at publishing a site. Thanks
Edit:
Could not find a part of the path 'C:\HostingSpaces\hannahha\hannahhamlin.co.uk\wwwroot\Assets\Common\images'.
This is the error it displays. This leads to me a problem I knew i was going to have to confront anyway. How do I include necessary directories for publishing?
First, that's not an error log. That's IIS' default request log. All it tells you is that a client using a particular browser requested /Login via GET. In other words, nothing at all useful to this issue.
You need a real error, with a stacktrace. You can either turn off custom errors temporarily (<customErrors mode="Off" /> in your Web.config), install something like Elmah to log errors for you, or use remote debugging.
However, most likely, the connection string only works locally, and the error you would see is just a DB connection error. It's rare that the connection string you'd be using in development would match exactly with what would be required for production, so you should utilize config transforms to change it when publishing.
That's assuming of course you even have a database server set up in production to connect to. Visual Studio employs a lot of database magic to allow you to focus on your code rather than menial implementation details like connecting to a database. However, when you go live, the training wheels are off, and you're responsible for making sure everything necessary is wired up. If you don't have a database server, install one. If you don't have a database, create one. Then, just alter your connection string to connect to that.
UPDATE
The error message is so far removed from this question was originally about, I think you would be best served by creating a new question and deleting this one.
That said, I'm not sure what you're trying to achieve exactly, but anything under your project directory will be published along with your site (except certain special directories like App_Data). If the files you're referencing are in some directory outside of your project directory, they will not be included, and there's really not a way to include them. You can, however, create a build action that copies the files somewhere under your project, and by virtue of that, they should then be published.

Entity Data Model attempting to create database, rather than use existing

I cannot figure out why I'm receiving the above error in my ASP.NET MVC site.
Some background, this site has existed and has been working in my DEV environment for several months. I'm using SQL Server and the ADO.NET Entity Data Model to `Update the Model from the Database'. Recently, I did some pretty large updates that involved changing a few tables around. Then I began receiving this error.
What I've tried:
Clearing browser cache, and using different browsers
deleting all generated tables in the .EDMX file and re-updating them
deleteing the .EDMX file entirely and recreating it
confirming my connection strings (the web.config hasn't been updated at all)
the server is working fine. I can use it in all other apps and SSMS
begging to no one in particular
below is the connection string created:
<add name="RetailDB" connectionString="metadata=res://*/Helpers.RetailDB.csdl|res://*/Helpers.RetailDB.ssdl|res://*/Helpers.RetailDB.msl;provider=System.Data.SqlClient;provider connection string="data source=****;initial catalog=RetailDatabase;persist security info=True;user id=******;password=******;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I'm sure this is probably something I'm overlooking, but I don't understand why it has decided to start trying to create the database itself. Please let me know what other information I can provide.

Can't connect to shared hosting database with site

Slightly at my wits end. Built an application, running fine locally. Migrated my database to MSSQL without issue, uploaded the site, can't seem to get the application to connect to the database. Any page that accesses the database I get a generic error message.
I've tried all the separate combinations of connection strings I could think of using the Godaddy recommended connection strings. Perhaps I am overlooking something simple?
I'm using Entity Framework Code-First -- My context model is called CombosContext.
<add name="CombosContext" connectionString=" Server=jelatin.db.9508732.hostedresource.com; Database=jelatin; User ID=jelatin; Password=********; Trusted_Connection=False" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString=" Server=jelatin.db.9508732.hostedresource.com; Database=jelatin; User ID=jelatin; Password=********; Trusted_Connection=False" providerName="System.Data.SqlClient" />
Server: jelatin.db.9508732.hostedresource.com
DB name: jelatin
user: jelatin
Table: Comboes
I'm unfamiliar with GoDaddy hosted SQL, but usually a connection string to MS SQL Server uses "Data Source" instead of "Server" and "Initial Catalog" instead of "Database".
UPDATE
I didn't realize Server and Database were allowed options in the Connection String. Sorry for the confusion.
Regarding the database itself - are you letting EF create the database? Does the user have permission on GoDaddy's system to create a database?
If you have already created the database, did you populate anything? I have found that EF Code First won't correctly populate the database if the database exists and the metadata table doesn't. If you can, try copying your local database up to GoDaddy, and see if the connection works.
Finally, for your generic error message - is it coming back in a 500 error? If so, have you tried using either IE or Chrome's dev tools to inspect the response? Better error information is usually hidden in there.

Categories

Resources