将C#MVC源代码连接到本地主机数据库

时间:2018-11-22 14:09:35

标签: c# asp.net json model-view-controller aspnetcoretemplatepack

我正在一家新公司开始工作,我应该开始使用其他人在.net核心MVC中开发的系统。

我有数据库的本地副本和代码的本地副本。 我可以访问SQL Server数据库并在SQL Server 2014中发出自己的SQL请求,不幸的是,我无法将Visual Studio代码连接到我的数据库并使所有内容在本地运行。

我尝试加载“ Views \ Home \ Index.cshtml”,页面开始在“ localhost:45896”加载,几秒钟后出现以下错误:

似乎该路径未正确写入json文件中,但我不确定如何以其他方式写入它。

也许还有其他东西。

连接字符串:

  

“ ConnectionStrings”:{       “ DefaultConnection”:“服务器= / SQLExpress;数据库= something_article;用户   Id = admins; Password = Admin;“,       “ EntityFrameworkConnection”:“数据源= 172.16.10.5;初始目录=公司名_通用;持久性安全信息= True;用户   id = admin; password = azerty; MultipleActiveResultSets = True; App = EntityFramework“”   }

谢谢

最好的问候 瑞

  

启动应用程序时发生错误。 Win32Exception:Le   chemin d'accèsspécifién'est pasvalide

     

未知位置SqlException:异常错误或特殊情况   àl'instance s'est product lors de l'établissementd'uneàà   SQL Server。可以从头到尾享用美食。   正确的实例名称和正确的SQL Server评估   配置自动连接程序的区别。 (提供者:命名   管道提供者,错误:40-不可能的连接和SQL   服务器)

     

System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity   身份,SqlConnectionString connectionOptions,SqlCredential   凭证,对象providerInfo,字符串newPassword,SecureString   newSecurePassword,布尔重定向用户实例,SqlConnectionString   userConnectionOptions,SessionData reconnectSessionData,   DbConnectionPool池,字符串accessToken,布尔   applyTransientFaultHandling)

Win32Exception: Le chemin d’accès spécifié n’est pas valide
     

System.ComponentModel.Win32Exception(0x80004005):访问权限   确认有效的

     

SqlException:实例发生异常情况   SQL Server的最佳产品。   可以从头到尾享用美食。 Vérifiezque le   实例名正确和SQL Server EST配置   专制人员关系消失。 (提供者:命名管道提供商,   错误:40-无法连接到àSQL Server)

System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
     

身份,SqlConnectionString connectionOptions,SqlCredential   凭证,对象providerInfo,字符串newPassword,SecureString   newSecurePassword,布尔重定向用户实例,SqlConnectionString   userConnectionOptions,SessionData reconnectSessionData,   DbConnectionPool池,字符串accessToken,布尔   applyTransientFaultHandling)       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions   选项,DbConnectionPoolKey poolKey,对象poolGroupProviderInfo,   DbConnectionPool池,DbConnection owningConnection,   DbConnectionOptions userOptions)       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool   池,DbConnection owningObject,DbConnectionOptions选项,   DbConnectionPoolKey poolKey,DbConnectionOptions userOptions)       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection   owningObject,DbConnectionOptions,userOptions,DbConnectionInternal   oldConnection)       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection   owningObject,DbConnectionOptions,userOptions,DbConnectionInternal   oldConnection)       System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection   owningObject,uint waitForMultipleObjectsTimeout,布尔允许创建,   仅boolOneCheckConnection,DbConnectionOptions userOptions,输出   DbConnection内部连接)       System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection   owningObject,TaskCompletionSource重试,   DbConnectionOptions userOptions,出DbConnectionInternal连接)       System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection   owningConnection,TaskCompletionSource重试,   DbConnectionOptions userOptions,DbConnectionInternal oldConnection,   出DbConnectionInternal连接)       System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection   externalConnection,DbConnectionFactory connectionFactory,   TaskCompletionSource重试,DbConnectionOptions   userOptions)       System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource   重试)       System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource   重试)       System.Data.SqlClient.SqlConnection.Open()       Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection()       Hangfire.SqlServer.SqlServerStorage.UseConnection(DbConnection privateConnection,Func func)       Hangfire.SqlServer.SqlServerStorage.UseConnection(DbConnection专用连接,操作操作)       Hangfire.SqlServer.SqlServerStorage.Initialize()       Hangfire.SqlServer.SqlServerStorage..ctor(字符串名称OrConnectionString,SqlServerStorageOptions选项)       Hangfire.SqlServerStorageExtensions.UseSqlServerStorage(IGlobalConfiguration   配置,字符串名称OrConnectionString,SqlServerStorageOptions   选项)       SofedisWebsite.Startup.b__4_6(IGlobalConfiguration   m)在Startup.cs中

                m.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection"),
     

新的SqlServerStorageOptions()

     

Hangfire.HangfireServiceCollectionExtensions + <> c__DisplayClass1_0.b__10(IGlobalConfiguration   配置)   Hangfire.HangfireServiceCollectionExtensions.GetInitializedJobStorage(IServiceProvider   服务提供者)   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactoryService(FactoryService   factoryService,ServiceProvider提供程序)   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor.VisitCallSite(IServiceCallSite   callSite,TArgument参数)   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite   scopedCallSite,ServiceProvider提供程序)   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite   singletonCallSite,ServiceProvider提供商)   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor.VisitCallSite(IServiceCallSite   callSite,TArgument参数)   Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(IServiceCallSite   callSite,ServiceProvider提供商)   Microsoft.Extensions.DependencyInjection.ServiceProvider + <> c__DisplayClass16_0.b__0(ServiceProvider   提供者)   Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type   服务类型)   Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider   提供者,输入serviceType)   Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider   提供者)   Hangfire.HangfireApplicationBuilderExtensions.UseHangfireServer(IApplicationBuilder   应用程序,BackgroundJobServerOptions选项,   IEnumerable AdditionalProcesses,JobStorage   存储)SofedisWebsite.Startup.Configure(IApplicationBuilder应用,   IHostingEnvironment env,ILoggerFactory loggerFactory,   IApplicationLifetime appLifetime,FileServerProvider   fileServerprovider)在Startup.cs中

                app.UseHangfireServer(new BackgroundJobServerOptions()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder
     

app)       Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter + <> c__DisplayClass3_0.b__0(IApplicationBuilder   应用程式)       Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter + <> c__DisplayClass0_0.b__0(IApplicationBuilder   建造者)       Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

     

.NET Framework X64 v4.0.30319.42000 |
  Microsoft.AspNetCore.Hosting版本1.1.1 |微软Windows   10.0.10586 |需要帮助吗?

2 个答案:

答案 0 :(得分:0)

在网络配置中添加连接字符串

configuration标记内

<connectionStrings>
  <add name="connectionname" 
       connectionString="Server=localhost; Database=dbname;
       Integrated Security=True"; providerName="System.Data.SqlClient" />
</connectionStrings>

并使用以下命令读取该连接字符串:-

System.Configuration.ConfigurationManager.
    ConnectionStrings["connectionname"].ConnectionString;

答案 1 :(得分:-1)

在Web.config文件中配置连接字符串TAG。

用户例如以下站点:

https://www.connectionstrings.com/