Error Connecting to DB.mdf when published IIS - c#

I have been searching all over different sources in search on solving my issue.. I've published a website on IIS that I have been working on and this is my first published website on IIS.
I seem to not be able to connect to the database.
I will provide everything that I have done right down here..
Appreciate any help please....
My web.config file in the published website directory C:\FinancialHubTest.
On a side note I also tried adding User Instance=True to my connection string in my web.config file but it doesn't work..
<connectionStrings>
<!--<add name="ConnStr" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFileName=|DataDirectory|\FinancialHub.mdf;Integrated Security=True" />-->
<add name="ConnStr"
connectionString="Data Source=(LocalDB)\.\IIS_DB;Integrated Security=True;" />
</connectionStrings>
Details of MSSQLLocalDB from cmd
applicationHost file in C:\Windows\System32\inetsrv\config edited with Notepad2.
I'm using FinancialHub as my applicationPool for my published website in IIS
<applicationPools>
<add name="DefaultAppPool" managedRuntimeVersion="v4.0" />
<add name="Classic .NET AppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
<add name=".NET v2.0 Classic" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
<add name=".NET v2.0" managedRuntimeVersion="v2.0" />
<add name=".NET v4.5 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" />
<add name=".NET v4.5" managedRuntimeVersion="v4.0" />
<add name="FinancialHub" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
<applicationPoolDefaults managedRuntimeVersion="v4.0">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="false" />
</applicationPoolDefaults>
</applicationPools>
My Published Website directory with App_Data having the FinancialHub.mdf file
My SQL Server Object Explorer, the connection only appears when I run my website via Visual Studio 2015 I think that would be running on IIS Express..
I have been getting this error every time I change here and there but I'm really sure why.. Or rather what changes I make to either web.config, etc will cause this error. I check the windows event log too.
I also followed these 2 links on dealing with this issue,
Using LocalDB with Full IIS, Part 1: User Profile,
Using LocalDB with Full IIS, Part 2: Instance Ownership
If there is a need for more information i can provide..
I feel like i have been beating around the bush trying to figure out but i can't seem to solve it..
I really do appreciate any help please. Thank you so much.

You are still using LocalDB even after publishing the application to IIS. LocalDB (SQL Database inside App_Data) is primarily intended for developing and testing purpose only.
You need a real SQL Server when you host the site on IIS. So you need to install SQL Server either in the same server that the application is hosted or a dedicated SQL server. Then attach or copy the existing database to SQL Server.

Related

C# .net MVC, set path to Google Application Credentials JSON file

I've just got this Google Sample Project to work on my VS2015,
However, after I published to "IIS" and host it, when I opened the link, the web page kept showing this message as the picture showed
I added the key to the web.config, but still doesn't work, just wondering if anyone had done this before, I really need help, thank you!
Edit: Here is my code
Web.Config
<appSettings>
<!-- Set to your Google project id as shown on the Google Developers Console -->
<add key="GoogleCloudSamples:ProjectId" value="gdtest-1332" />
<add key="GOOGLE_APPLICATION_CREDENTIALS" value="D:\ProjectCloud\gdtest-12323.json" />
<!--
Set to either mysql or datastore.
If using mysql, update the connectionString far below, and then run Update-Database in the
Package Manager Console.
-->
<add key="GoogleCloudSamples:BookStore" value="datastore" />
<!-- Set to your Google Cloud Storage bucket -->
<add key="GoogleCloudSamples:BucketName" value="cloudstoragetestbillez" />
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
Programmatically set an environment variable at runtime as such:
string credential_path = #"C:\..\key.json";
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);
I'm not an expert with IIS but it won't seem to pick up on environment variable set in your desktop environment.
Restarting the Visual Studio 2017 did it for me for Console Application.
Console.WriteLine(System.Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
From google documention it seems it is env var and not web.config.
If you are using a service account credential, set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path to the JSON credential file you downloaded.
With command prompt:
set GOOGLE_APPLICATION_CREDENTIALS=[PATH_JSON]
You donĀ“t need setting credentials on code
Google says:
After creating a service account, you have two choices for providing the credentials to your application. You can either set the GOOGLE_APPLICATION_CREDENTIALS environment variable explicitly, or you can pass the path to the service account key in code.

how to redirect from folder in a web server

i have two different applications, one is a website project running on the the server root, the second is a web application project in a folder, both projects have their configuration files, and i am putting the link in the configuration file of the website project
i am trying to redirect users from the website project to the web application project, whenever i use this:
<add key="CoronaPortalAddress" value="http://localhost/coronaportal/Security/ApplicantSignIn1.aspx?applicationType=" />
<add key="CoronaPortalSignInPage" value="http://localhost/coronaportal/Security/SignIn.aspx" />
<add key="CoronaPortalTimeTablePage" value="http://localhost/coronaportal/Conona Schools_ Trust Council_ApplicantTestScores/TimeTable1.aspx" />
<add key="CoronaPortalResultsPage" value="http://localhost/coronaportal/ParentReportLogin.aspx" />
users will be redirected, though on the url it will showing localhost, so i change it to:
<add key="CoronaPortalAddress" value="http://www.shodsystems.com/coronaportal/Security/ApplicantSignIn1.aspx?applicationType=" />
<add key="CoronaPortalSignInPage" value="http://www.shodsystems.com/coronaportal/Security/SignIn.aspx" />
<add key="CoronaPortalTimeTablePage" value="http://www.shodsystems.com/coronaportal/Conona Schools_ Trust Council_ApplicantTestScores/TimeTable1.aspx" />
<add key="CoronaPortalResultsPage" value="http://www.shodsystems.comcoronaportal/ParentReportLogin.aspx" />
now it throwing error:
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS
i tried to google this, but couldnt fix it, any assistance would be appreciated.

Upgrading Umbraco 7.2.8 to 7.3.0

I am currently working on Umbraco Upgrade.
My Current version of Umbraco is 7.2.8 and I want to upgrade it to 7.3.0.
I have upgraded successfully but now i am trying to execute project it shows me below error :
Is there anything that have to be changed in database? Because i have upgraded via nuget.
Please help me out from this situation.
1) In the web.config try to set the umbracoConfigurationStatus to emty, this will force a upgrade process:
<appSettings>
<add key="umbracoConfigurationStatus" value="" />
2) In the Web.config check the umbracoDbDSN connectionstring. If you use a .sdf file check if the file exists. Else check the connection.
<connectionStrings>
<remove name="umbracoDbDSN" />
<add name="umbracoDbDSN" connectionString="Data Source=|DataDirectory|\Umbraco.sdf;Flush Interval=1;" providerName="System.Data.SqlServerCe.4.0" />
<!-- Important: If you're upgrading Umbraco, do not clear the connection string / provider name during your web.config merge. -->
</connectionStrings>
3) Your database file is corrupted. restore the .sdf file from a backup, or try the repair tool. http://sqlcecmd.codeplex.com/ see https://technet.microsoft.com/en-us/library/ms172420.aspx
Or the database file is locked or somethings by another process, restart the computer

host a database website with entity framework in the production server

I developed an asp.net website (using webforms) and for database connection I used Entity Framework. On my local computer everything is working fine. Now I try to host it I am having a problem. I have copied my files to the production server and attached my SQL Server database and set my connection string to:
<add name="ConnectionString"
connectionString="Data Source=SQL5003.Smarterasp.net;Initial Catalog=DB_9C4561_WFormBlog;User Id=DB_9C4561_WFormBlog_admin;Password=mydbpwd"
providerName="System.Data.EntityClient" />
but when I test my website am getting error:
Keyword not supported: 'data source'
When I removed "data source", it started complaining of "Initial catalog" keyword not supported.
Please help me out. You can refer me step by step tutorial or material that can put me through. Thanks in advance!
Try the below format, I have my database on smarterasp.net and it works well
<connectionStrings>
<clear />
<add name="ConnectionString" connectionString="Persist Security Info=False;database=DB_9C4561_WFormBlog;server=SQL5003.Smarterasp.net;user id=DB_9C4561_WFormBlog_admin;password=mydbpwd;Current Language=English;Connection Timeout=60;" />
</connectionStrings>

The process cannot access the file \App_Data\ASPNETDB.MDF' because it is being used by another process.

When trying to publish our website on Windows Server 2008 R2, we are seeing the following error. Error 4 The process cannot access the file 'C:\Users\Student\Desktop\CSFP Front-End\App_Data\ASPNETDB.MDF' because it is being used by another process.
We don't understand what else could be using the data file.
web.config looks like this
<connectionStrings>
<add name="FBConnectionString" connectionString="Data Source=SERVER4;Initial Catalog=AITP;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Student\Desktop\CSFP Front-End\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True"/>
</connectionStrings>
<system.web>
It runs fine locally, and the roles and users work as well. "Build Web Site" also works just fine, but when we are trying to publish the website it throws the error. Any ideas?
while publish the project, first detach the database file. Then publish it will work fine. For detaching right click on App_Data->ASPNETDB.MDF, detach...
The simplest solution could be to simply close the .mdf file and restart Visual Studios. I've had to do this when felix's method doesn't work.
Another superstition I try is killing the "SQL Server" process with the Task Manager.

Categories