Ive been working on a web app for the past month and now its time to deploy it on real windows server.The problem is once i deployed it my default localdb code first SQL database no longer works with this code:
[SqlException (0x80131904): 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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
)]
Source Error:
Line 11: var manager = new UserManager();
Line 12: var user = new ApplicationUser() { UserName = UserName.Text };
Line 13: IdentityResult result = manager.Create(user, Password.Text);
Line 14: if (result.Succeeded)
Line 15: {
my web.config string :
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346;AttachDbFilename=|DataDirectory|\aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
Its so frustrating im kinda lost , i dont want to build my login and registration from scratch i just want to use the provided ones from Visual Studio 2017 and there is no tutorial up to date how to do it.
I have SQL Express on my computer installed and its currently running.
There are possible solutions to solve LocalDB instance issue:
1) If the database is already created (as given by AttachDbFilename=|DataDirectory|\aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346.mdf), remove the section so that it only contains Initial Catalog shown below.
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-projecttwo-80a6f83e-fca9-45c3-869f-c5c625497346;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
2) Set IIS application pool for the MVC application to either LocalSystem or NetworkService from ApplicationPoolIdentity - if you suspect a permission-related issue for the application.
3) Find out \%WinDir%\System32\inetsrv\config\applicationHost.config file and enable setProfileEnvironment="true" (restart the application pool afterwards):
<!-- use application pool name depending which pool that your MVC site used -->
<add name="DefaultAppPool" ...>
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
Further references:
SQL Server Connection Strings
Using LocalDB with Full IIS Series: (Part 1) (Part 2)
Similar issue:
Deployment of SQL Express LocalDB on IIS
Related
I have built MVC 5 Web application in .net 4.7.2. It runs fine in my local machine. Update and Delete commands were failing, which I have now sorted out thanks to this post: DELETE/PUT verbs result in 404 Not Found in WebAPI, only when running locally, I added this line to the web.config and all the CRUD now works:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0
However, when I publish the application to my hosting server it breaks at this line in the web.config.
When I remove the line only Create and Retrieve data works, but Update and Delete fails with the error:
Object reference not set to an instance of an object.
at this line in the Index view: Line 40: #For Each item In Model
I understand this is because the model is null/nothing at this point.
This is my delete function showing where the error starts...
Public Function Delete(ByVal id As Integer) As ActionResult
Dim Client As HttpClient = New HttpClient()
Client.BaseAddress = New Uri(myWeb & "AppMenuCRUD")
Dim APIConsumer = Client.DeleteAsync("AppMenuCRUD/" & id.ToString())
APIConsumer.Wait()
Dim Result = APIConsumer.Result << failure here: Error 404
If Result.IsSuccessStatusCode Then
Return RedirectToAction("Index")
End If
Return View("Index")
End Function
The hosted server is running Windows Server 2016, .Net 4.7.2. I have enabled read/write to the website folder.
This is my IIS Settings in the hosting server:
UPDATES:
Having looked further into this, my hosting server is now updated to .net 4.8 and everything now just fails. I am now not able to even load the index view page. It breaks at the same line 40 as above.
In IIS, my application pool is set to integrated, .net 4.0. I cannot see anything higher from the dropdown list.
In IIS, I have nothing filtered in the list of HTTP Verbs, which I believe means it should accept anything.
UPDATE 2
After the updates to .net 4.8, I am now getting a new error
Lock Violation
I have enabled everything in the IIS, including changing all the ASP Configurations from Read Only to Read/Write.
I'm fearing I may introduce vulnerabilities to the VPS...
Is there anything else I need to do to get this to work?
Sometimes you need to update manually the Web.config when you change the target framework, please double check those lines:
<system.web>
<compilation debug="true" targetFramework="4.8">
<httpRuntime targetFramework="4.8" />
...
So, this is how I finally got it to work:
I am hosted with Plesk as 'control cpanel'. Apparently, Plesk has some lock which I had to unlock here:
Plesk > Tools & Settings > Security > Prohibit the ability to override handlers
Thanks to https://support.plesk.com/hc/en-us/articles/115000287305-Site-shows-500-19-Internal-Server-Error-Config-Error-Lock-violation. I was quite surprised my host could not help with this!
In the gymnastics of enabling everything else in my VPS, I ended up enabling/installing WebDAV. This also apparently does not 'allow' Edit/Delete actions. Instead of uninstalling it, I sorted it out from the web.config like this:
<system.webserver>
...
Thanks to Web API Put Request generates an Http 405 Method Not Allowed error
I realize there's similarly titled posts here, I've searched through all of them without finding my solution.
I'm uploading an Excel file to SQL Server in ASP.net MVC. Here's my connection string:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication12-20180107114522.mdf;Initial Catalog=aspnet-WebApplication12-20180107114522;Integrated Security=True;" providerName="System.Data.SqlClient" />
And here's my Excel file connection string:
string constr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", filepath);
The rest of my code uses SqlConnection / SqlCommand etc, rather than oleDB commands.
You use SqlConnection to connect to SQL Server databases. That connection type doesn't understand "Provider" in the connection string.
You need to use the appropriate connection type for Jet databases, e.g. OleDbConnection.
I've been spinning my wheels on this for awhile now and haven't been able to find anything substantial on the topic.
I've implemented an MVC 6 project that is utilizing the Identity Framework 2 and Entity Framework 6. The application works fine with a local database being used as my identity repository. On the first connection, the Entity Framework creates the identity tables based on my identity model classes. I built it based off of a project from this book. The chapters on using Identity and all of the online samples I find don't cover pointing the entity framework to a remote database.
Here are my connection strings I've experimented with...
Local database connection string. Project works fine.
<add name="IdentityDb" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\IdentityDb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
Failed approach 1. I based this off of other connection strings from my other projects. I removed the meta data parameters because when it comes to my understanding, this points to the edmx file but I don't have one since I'm taking a code first approach and letting identity and the entity frameworks build the database. I'm wondering if I'm missing something here because I've always taken a database first approach until now.
<add name="IdentityDb" connectionString="provider=System.Data.SqlClient;provider connection string="data source=****;initial catalog=IdentityTest;Uid=*****;Pwd=*****;integrated security=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Returned exception details. The metadata keyword is missing.
System.ArgumentException: Some required information is missing from the connection string. The 'metadata' keyword is always required.
Failed approach 2. I built an empty Identity.edmx file thinking this must be where all of the metadata is stored and maybe the entity framework will update it and have it's required resources once the app connects to the database the first time.
<add name="IdentityDb" connectionString="metadata=res://*/Identity.csdl|res://*/Identity.ssdl|res://*/Identity.msl;provider=System.Data.SqlClient;provider connection string="data source=****;initial catalog=IdentityTest;Uid=****;Pwd=****;integrated security=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Returned exception detail. The meta data is missing.
System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource.
Last failed approach. I found a lot of online sources where people simply changed the metadata parameters to "res://*". I'm guessing this is some kind of wildcard that would locate the metadata resources if they existed...
<add name="IdentityDb" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string="data source=****;initial catalog=IdentityTest;Uid=****;Pwd=****;integrated security=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Returned exception details (With a identity.edmx file in the project)
System.NotSupportedException: Model compatibility cannot be checked because the DbContext instance was not created using Code First patterns. DbContext instances created from an ObjectContext or using an EDMX file cannot be checked for compatibility.
Returned exception details (Without an identity.edmx file in the project)
System.ArgumentException: Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied
My database context class
public class AppIdentityDbContext : IdentityDbContext<AppUser>
{
public AppIdentityDbContext() : base("name=IdentityDb") { }
static AppIdentityDbContext()
{
// Seeds the database when the schema is first created through the Entity Framework.
Database.SetInitializer<AppIdentityDbContext>(new IdentityDbInit());
}
// OWIN uses this method to create instances of this class when needed.
public static AppIdentityDbContext Create()
{
return new AppIdentityDbContext();
}
public System.Data.Entity.DbSet<UAM.Models.Identity.AppRole> IdentityRoles { get; set; }
}
// Seed class for initially populating the identity database.
public class IdentityDbInit : DropCreateDatabaseIfModelChanges<AppIdentityDbContext>
{
protected override void Seed(AppIdentityDbContext context)
{
PerformInitialSetup(context);
base.Seed(context);
}
public void PerformInitialSetup(AppIdentityDbContext context)
{
// Initial database configuration
}
}
Any help or insight would be much appreciated. What is the correct approach for doing this? Is there something that I need to do when I transition from using a local database to a remote one? Let me know if I should provide anymore code samples. I'm fairly new to MVC and am currently building this module so that I can use it for a few enterprise applications that I'll be developing this year.
You need to specify providerName="System.Data.SqlClient" instead of providerName="System.Data.EntityClient"
For Example
<add name="IdentityDb" connectionString="Data Source=*******;Database=IdentityTest;Integrated Security=false;User ID=**;Password=******;" providerName="System.Data.SqlClient"/>
This is the connection string I use and it worked without an issue.
<add name="InventoryEntities"
connectionString="metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;provider=System.Data.SqlClient;provider connection string="data source=.\sqlinstance;initial catalog=DBName;persist security info=True;user id=UID;password=PWD;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
The tool generated this for me (I didn't need to do anything custom to the connection string) so maybe you can delete and let the too re-add it? (I think it does that)?
Also, you didn't rename the EF files at all did you? If you did, you would have to update the connection string to match.
What is the correct format of the Oracle connection string in MVC 6?
My dependencies:
"EntityFramework": "5.0.0",
"Oracle.ManagedDataAccess": "12.1.2400",
"Oracle.ManagedDataAccess.EntityFramework": "12.1.2400",
My connection string :
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Data Source=myHost:myPort/mydb;User Id=myUser;Password=myPassword"
}
}
}
Reported error:
{"An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct."}
In MVC 5 I use this:
<add name="DefaultConnection" connectionString="metadata=res://*/App.csdl|res://*/App.ssdl|res://*/App.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="DATA SOURCE=myHost:myPort/myDb;PASSWORD=myPassword;PERSIST SECURITY INFO=True;USER ID=myUser;Connection Timeout=900"" providerName="System.Data.EntityClient" />
In your Example your are using Managed Driver as Data Provider to use oracle DB.
But in your EF connection string your are mentioning different Provider (providerName="System.Data.EntityClient") while you should use (providerName="Oracle.ManagedDataAccess.Client")
See correct connection string below :
<add name="TestContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=test;Password=testpassword;Data Source=eftest" />
For more details Please refer to the following link :
https://docs.oracle.com/cd/E56485_01/win.121/e55744/InstallEntityConfig.htm#ODPNT8266
I'm working on my first real MVC project and my task is to implement a custom membership provider. I have implemented one before in asp.net 3.5 Web Forms so I'm trying to reuse some of that code if possible.
Our data comes from a remote web service so I won't be using any of the standard membership database.
Based on some research and experience in Web Forms I created my class:
public class wwdllMembershipProvider : MembershipProvider
I put the following in web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<membership defaultProvider="wwdllMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<add name="wwdllMembershipProvider" type="wwdllMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" writeExceptionsToEventLog="false" enablePasswordChange="true" />
</providers>
</membership>
From there I was just going to try to see if any of the stubbed out code in my membership provider was being hit. But as soon as I click on the login link in the app I get the following error:
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)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: 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)
Source Error:
Line 55: using (var context = new UsersContext())
Line 56: {
Line 57: if (!context.Database.Exists())
Line 58: {
Line 59: // Create the SimpleMembership database without Entity Framework migration schema
Source File: c:\Users\mburt\Documents\Visual Studio 2012\Projects\eSales\4300\Siriusware.eSales\Filters\InitializeSimpleMembershipAttribute.cs Line: 57
Which is puzzling to me because I didn't think the Simple Membership Provider code would execute because of the web.config setting disabling it.
Can someone point out to me what I'm doing wrong? Thanks!
The default account controller is decorated with that very attribute. Check if that is still present.
(Default MVC4 project code below.)
namespace MvcApplication2.Controllers
{
[Authorize]
[InitializeSimpleMembership]
public class AccountController : Controller
{
[...]
}
}