MVC Deploy Views missing - asp.net-mvc

Please help me a bit...
I have a domain with a web page, coded and compiled in VS2013, works like a charm... Then I decided to add a database, so I wrote one (ms sql). However, later when I deployed the project I can only watch the _Layout.cshtml file online, local everything looks perfect. What might be the problem? I've tried re-order some settings and scripts, but without success. A supplementary question, can the Connectionstring cause this? I've been having some problems with that nasty row.
This is my connectionstring for deploy:
<add name="20066_name" connectionString="Data Source=name-20066.mssql.domainaddress.com;Initial Catalog=20066-name;Integrated Security Info=True;User Id=secret;Password=secret" providerName="System.Data.SqlClient" />

So locally works fine with a local database, or using the connection string's remote database?
Try using the remote connection string with the local deployment and see if it connects. If it does, then you need to check the properties on the publish dialog. There is an option for altering the connection strings when you deploy (you might have heard this process as web.config transformation), so make sure that you send the correct connection string to the remote web server.
The connection string seems ok. You can experiment with more options though. Check the following link for ideas http://www.connectionstrings.com/sql-server/

Related

FSharp.Data.SqlCient works locally but not on production server

I am having an issue with FSharp.Data.SqlClient. I am building an Asp.net Core full framework 4.6 web app. The main project is in C# which references several projects that are in F#. Each of these F# projects use FSharp.Data.SqlClient for data access. When running the app locally everything works fine, but when I deploy it to azure I get the error "Instance Failure" when the F# code attempts to execute a query.
I have a suspicion that in some way it has to do with how the connection strings are being consumed or maybe some sort of runtime conflict between FSharp.Data.SqlClient and Entity Framework. Entity framework is in the main project to handle the membership data and nothing else. I have to specifically add a connection string to a config file in the main project so that the referenced F# projects can access the database at runtime. Entity framework consumes it's data string via the AppSettings.Json file. I am unaware if there is a better way to wire this up, but again, this works perfectly when I run it locally but not on the server that it's been deployed to.
Is there something that I need to enable or change code-wise for the app to work on the production server?
Here's a view of my data strings. In my F# project I have an app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data
Source=server code here"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
</configuration>
In that same F# project I have another file that I use to access the runtime connection string:
module internal DbAdmin
open FSharp.Data
open FSharp.Configuration
module Admin =
// runtime connection string
type private Config = AppSettings<"App.config">
let rtConnection = Config.ConnectionStrings.DefaultConnection
In the main C# project I have an app.config file:
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=server
code here" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
and in the appsettings.json is configured as this:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=Server code Here"
}
}
this is the actual query code:
type Select_AllArticles =
SqlCommandProvider<
"
select * from article.vw_AllArticlesAndDetails
", Admin.connectionString, ConfigFile = Admin.configFile
>
try
succeedWithMsg
(Select.Select_AllArticles.Create(Admin.rtConnection).Execute() |>
Seq.toList)
(createGoodMsg(OK("Some Success Message.")))
with
| ex -> fail (createBadMsg(DbError(ex.Message + " --selectAllArticles")))
**Update: **
After remote debugging the app, this is the entire error message it gives
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
This is odd to me as the connection string in use is the same one used by Entity Framework which seems to access the data base just fine.
New Update
Ok, I think I figured out what's going on. I believe it is definitely a config issue. So as I stated before, in development I had to create a config file in order to create a connection string that FSharp.Data.SqlClient could connect to. I couldn't figure out how to get it to connect to the connection string in the appsettings.json file. Perhaps someone can explain that to me, as that may be the best solution. Anyhow, I followed up on my assumption that the connection string inside of the config file wasn't getting updated on deployment by manually inserting the production server connection string, and then deploying the app. Sure enough the issue was gone, and everything worked normally. So, now the question is, what's the best way to get FSharp.Data.SqlClient connected to the connection string correctly in a core app that utilizes a appsettings.json file? How do I go about handling this issue? I need someone to walk me through it, as I'm new to this.
Current Status
So after realizing that it is indeed a config issue, the question now is how do I properly retrieve the connection settings from the appsettings.json file via my F# projects. Using the FSharp.Data json provider, I need to figure out how to properly locate the appsettings.json file for both production and development use. How can an F# project locate a file in the main project? Am I just overly complicating things?
You appear to be looking for App.config to find the connection string. That usually gets replaced with a different .dll.config file when deploying, though that doesn't appear to be the issue. Do you have a DefaultConnection in you Azure App Service connection strings that is incorrect? Other than that, I would suggest parsing the connection string from the appsettings.json rather than the app.config file.

ORA-12154: TNS:could not resolve the connect identifier specified (Oracle, ASP,Net, Dapper)

I can't find the exact issue I have on here or anywhere.
I have an ASP.Net MVC WebApi (MVC 5.1.0, Framework 4.5.1) project that uses Oracle.DataAccess. It runs on the local IIS server via a URL that's in my hosts file. It has a connection string connecting to an Oracle database. It works fine.
I have a 'normal' ASP.Net MVC (MVC 5.2.2, Framework 4.5.2) project that uses Oracle.ManagedDataAccess and Dapper. It runs on the local IIS server via a URL that's in my hosts file. It uses the SAME connection string (barring the providerName) to (attempt to) connect to an Oracle database. it does not work, throwing
ORA-12154: TNS:could not resolve the connect identifier specified
when I try to open the connection.
<add name="OurName" connectionString="Data Source=xxxxx_migration2;Persist Security Info=True;User ID=OurUserName;Password=thepassword;Enlist=False;Min Pool Size=10;Connection Lifetime=120;Connection Timeout=30;Incr Pool Size=5;Decr Pool Size=2;" providerName="Oracle.ManagedDataAccess.Client"/>
TNSNames.ORA is fine [as you'd reckon given that the exact same connection string works in the other project], there are no brackets in the project file paths (a very obscure issue I found in my researches), ORACLE_HOME is pathed... I am stumped.
I know Dapper extends the connection object - does it have any really funky weird requirements that might be causing this?
EDIT: If I switch the 'normal' ASP.Net MVC (and connection string providerName parameter) to Oracle.DataAccess, and don't use Dapper I can connect.
In the end, I needed to make more config file changes than I thought, in order to make Oracle.ManagedDataAccess work (Dapper was not an issue).
see this blog article
and the accepted answer here
It's a little bit annoying, and a change from the past situation to have to manually specify the location of TNSNAMES.ORA in the config file - but hey, it's a config file after all.
In my case, in Web.config file, oracle.manageddataaccess.client -> dataSources tag, alias name was wrong. Once changed, it worked.

mvc 4 I've deployed to production server. Now cannot connect to localdb

I finally have a published website. Now I want to continue development so I changed my webconfig back to the previous working localdb connection string.
<add name="HouseContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MVCBSV;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MVCBSV.mdf" providerName="System.Data.SqlClient"/>
and then commented out the connection string to the production server.
<!--<add name="HouseContext" connectionString="Data Source=bstatus2014.db.10188888.hostedresource.com; Initial Catalog=bstatus2014; User ID=bstatus2014; Password=Bstatus!2014;" providerName="System.Data.SqlClient" />-->
But when I run the project, the data that is retrieved is the production data! I've tried clean and then build solution but no effect. Probably related, is that I published to the local IIS following the web deploy suggestions adding an application pool. Also if I use the connection wizard specifying localdb/v11.0 it no longer shows my MVCBSV.mdf db.
Also I was trying to use transforms debug/release to make this change, but have found a post that transforms don't work on debug.
A beginner so explicit answers are a help.
Yea, if you publish to your local IIS then your application is probably tied to that site. Open IIS, find the published site open the folder your published code is in and then look at the Web config it is associated to it. Also try recycling the app pool.
Transforms should only be used when you are publishing to a non-local environment anyway. Beyond that if you publish it might make more sense if you published to a location in your file system.

What am I doing wrong with my deployed connection string?

I’m having a problem with my connection string after deploying. My site, www.coopersystems.net, is hosted by Godaddy. I’m using Visual Web Developer Express 2012 using E-Code First. Godaddy gave me the following connection string information:
Data Source=MyDatabaseName.db.10000000.hostedresource.com; Initial Catalog=MyDatabaseName; User ID=MyDatabaseName; Password='MyDatabasePassword';
I then used this info to change my connection string to the following:
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=MyDatabaseName.db. 10000000.hostedresource.com; Initial Catalog = MyDatabaseName; User ID=MyDatabaseName; Password=’MyDayabasePassword’;Integrated Security=True" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="ApplicationServices" connectionString="Data Source=MyDatabaseName.db. 10000000.hostedresource.com; Initial Catalog = MyDatabaseName; User ID=MyDatabaseName; Password='MyDatabasePassword';Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
The default page shows up fine but clicking on the tabs that should load other pages does not work. The page seems to hang for a while then the error page shows with error: “We’re sorry, we’ve hit an unexpected error. Click here it you’d like to go back and try again”.
My first question is:
1: If my connection string is wrong, would my default page still load? I ask this because when I tried changing keyword/value the home page would not load.
2: Is there something other than my connection string that I may be able to check?
3: How can I solve this problem?
Any suggestions or help would be greatly appreciated. I’m going on my second week of trying to get Godaddy to help and using their forums. Nothing has worked yet.
Latest attempts:
So I fixed the password quotes and had godaddy configured the config file to show the error message..
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I assume the server not found to mean that I provided the wrong name for a server on the Web Publish wizard so I’ve been trying different combinations of Server Name, Site Path, and Destination URL.. I got the site deployed with a few combinations of those values but the links still wont work.
Is there a configuration that maybe I should’ve done before using the “Publish” function of Web Developer Express 2012? I am out of ideas and Godaddy can’t help.
After one week of trying I decided to try to connect to the database using IIS 7.5. I can't connect with this either so I guess If I can solve connecting to the site or database with IIS I should be able to solve my other problems. Please help if you can. Thanks.
Try removing the single quotes around the password:
Password=MyDatabasePassword
Turns out that my ISP is blocking port 1433. No mater what I do I can't access the database.

Trouble deploying EF CodeFirst to server

I have a CodeFirst web application that originally used LocalDb. I changed the connection string to:
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SqlExpress;Initial Catalog=aspnet-BatchFindings;Integrated Security=True" />
And I created the appropriate database using Server explorer.
I am using WebDeploy to publish to a Windows Server 2012 instance running IIS8.
After publishing, I was unable to use the application; it did not have permissions for the database. I then changed the identity to a user account, and now I do not get database errors. Except the application does not appear to save any data to the database. I am at a complete loss - any help is appreciated!
Recap:
Entity Framework, Code First
Web Deploy to IIS 8
Custom Application Pool, identity set to a user account
Data not being stored in database.
EDIT: I would love to be able to simply use Web Deploy and have it use its own database (so it does not get test data from mine) but this is just so frustrating! I am publishing, the connection string should work, not sure where I am going wrong.
Stupid question but are you calling DbContext SaveChanges() method after data manipulation - data saving works when testing?
Also you can use different web.config files when testing (Debug) and deploying (Release version).
So I inadvertently figured out the reason why it was not saving. For some reason in my test environment everything worked, but when it was pushed out, I needed to add the following line:
db.Entry(obj).State = System.Data.EntityState.Added;
I checked out the tutorial, which seemed to work until it went into that Grant.sql file. There is no option in Visual Studio to connect.
What I ended up doing in that case to get the database working was set my Application Pool to run under a user identity I created for this purpose, while setting Load User Profile to True. You can also run as LocalSystem (as long as you create the following folder: C:\Windows\SysWOW64\config\systemprofile\Desktop - this tricks the system into thinking the LocalSystem account is interactive).

Resources