2

I published my application and got this error:

An error occurred while starting the application.

.NET Core X64 v4.1.1.0 | Microsoft.AspNetCore.Hosting version 1.1.1 | Microsoft Windows 10.0.14393 | Need help?

See the log File:

Application startup exception: System.FormatException: Could not parse the JSON file. Error on line number '9': '"ConnectionStrings": {
"EstudantesCV21Context": "Provider=SQLOLEDB.1;Password=******;Persist Security Info=True;User ID=sa;Initial Catalog=EstudantesCV21Context-241ea716-db64-402d-955f-be4b264ce053;Data Source=*********"'. ---> Newtonsoft.Json.JsonReaderException: Bad JSON escape sequence: \S. Path 'ConnectionStrings.EstudantesCV21Context', line 9, position 209.
   at Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char quote)
   at Newtonsoft.Json.JsonTextReader.ParseString(Char quote, ReadType readType)
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationFileParser.Parse(Stream input)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at EstudantesCV21.Startup..ctor(IHostingEnvironment env) in C:\Users\erito\onedrive\documentos\visual studio 2017\Projects\CadastroCV21\EstudantesCV21\Startup.cs:line 26
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.AspNetCore.Hosting.Internal.StartupLoader.LoadMethods(IServiceProvider hostingServiceProvider, Type startupType, String environmentName)
   at Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.<>c__DisplayClass1_0.<UseStartup>b__1(IServiceProvider sp)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureStartup()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Hosting environment: Production
Content root path: C:\WebSite
Now listening on: http://localhost:18998
Application started. Press Ctrl+C to shut down.

connection string:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "ConnectionStrings": {
    "EstudantesCV21Context": "Server=myserver\SQLEXPRESS;Database=mydatabase;userid=myid;password=mypass"
  }
}
Eriton Silva
  • 129
  • 1
  • 10
  • did you look at this? http://stackoverflow.com/questions/35663759/asp-net-5-an-error-occurred-while-starting-the-application/35712042#35712042 – Muqeet Khan Apr 24 '17 at 20:49
  • I dont know, but I think not, I publish on Windows Server 16, and get this error after change my connection string. – Eriton Silva Apr 24 '17 at 21:00
  • That's not the resolution but follow that answer to see what the actual error is. "An error occurred while starting the application" is pretty generic to give anyone any real insight into solving your issue. – Muqeet Khan Apr 24 '17 at 21:03
  • I put log on question, i need fix the string connection. – Eriton Silva Apr 24 '17 at 21:29
  • what database are you connecting to... SQLOLEDB is really old and not used with SQL Server or SQLite for that matter with EFC... Can you show us your Connection String cause that would shed some light on the issue. – mvermef Apr 25 '17 at 05:29
  • I use sql server 2016, I will review my connection string Thanks. – Eriton Silva Apr 25 '17 at 17:27
  • I generate my connection string using data link properties, and past in my appssetings file but not work – Eriton Silva Apr 25 '17 at 17:38
  • If you get `startup` errors you can enable extra startup options to output the actual reason. Have a look at my blog post about it. http://pkula.blogspot.co.uk/2017/11/asp-net-core-how-to-fix-error-occurred.html – Piotr Kula Nov 15 '17 at 10:59

1 Answers1

1

I don't know if you still need an answer to this problem. I had this problem and I solved it by changing my connection string like this. Add double back slashes

{ "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Warning" } }, "ConnectionStrings": { "EstudantesCV21Context": "Server=myserver\\SQLEXPRESS;Database=mydatabase;userid=myid;password=mypass" } }

Emmac
  • 2,928
  • 2
  • 15
  • 22