C# 连接字符串从何而来?Asp.net
我正在Azure上运行一个带有Azure SQL数据库的Razor站点,但已经开始收到一条连接错误消息,说它无法连接到App_Data localdb—我不使用它。我还注意到,我的项目在没有要求的情况下,很友好地重新创建了一个localdb。我已经将Asp标识表迁移到我的azure sql数据库中,所以它都在一个地方(这是个好主意吗?我觉得是这样)。无论如何localdb消息让我感到困惑,因为据我所知,我的项目中没有对localdb的引用。My web.config有2个连接字符串: 我已经与Kudu进行了检查,这是网站实际的web.config上的内容-因此没有转换或发布连接字符串。但是如果我调试azure并查看C# 连接字符串从何而来?Asp.net,c#,asp.net,asp.net-mvc,azure,azure-sql-database,C#,Asp.net,Asp.net Mvc,Azure,Azure Sql Database,我正在Azure上运行一个带有Azure SQL数据库的Razor站点,但已经开始收到一条连接错误消息,说它无法连接到App_Data localdb—我不使用它。我还注意到,我的项目在没有要求的情况下,很友好地重新创建了一个localdb。我已经将Asp标识表迁移到我的azure sql数据库中,所以它都在一个地方(这是个好主意吗?我觉得是这样)。无论如何localdb消息让我感到困惑,因为据我所知,我的项目中没有对localdb的引用。My web.config有2个连接字符串: 我已
ConfigurationManager.ConnectionString
我看到4个连接字符串,而不是2个。最后2个来自my web.config,第2个为空,第1个为:
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true}
我不禁想知道这是怎么用的,在哪里用的
但是,查看ConfigurationManager.ConnectionStrings[DefaultConnection]是正确的。我的db模型初始化如下:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
...
public类ApplicationDbContext:IdentityDbContext
{
公共应用程序上下文()
:base(“DefaultConnection”,throwifvv1schema:false)
{
}
公共静态应用程序上下文创建()
{
返回新的ApplicationDbContext();
}
...
所以这是相当平淡无奇的。值得一提的是,我在尝试启用站点范围的SSL时遇到了这样的问题。我已经删除了该代码,但问题仍然存在:(
下面是关于我看到的错误的更多信息:
运行时发生与网络相关或特定于实例的错误
正在建立与SQL Server的连接。找不到该服务器,或者
无法访问。请验证实例名称是否正确,以及
SQL Server配置为允许远程连接。(提供程序:SQL)
网络接口,错误:26-定位服务器/实例时出错
(指定)
描述:在执行过程中发生未处理的异常
当前web请求。有关详细信息,请查看堆栈跟踪
有关错误的信息及其在代码中的来源
SQLExpress数据库文件自动创建错误:
连接字符串指定本地Sql Server Express实例
使用应用程序的App_数据目录中的数据库位置。
提供程序试图自动创建应用程序
服务数据库,因为提供程序确定该数据库
不存在
my web.config:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="data source=tcp:myweb.database.windows.net,1433;initial catalog=mywebtest;user id=myStdMobile;password=dfdfd;multipleactiveresultsets=True;connect timeout=30;encrypt=True;trustservercertificate=False;application name=EntityFramework" providerName="System.Data.SqlClient" />
<add name="DeveloperConnection" connectionString="data source=tcp:myweb.database.windows.net,1433;initial catalog=mywebtest;user id=myWebDbAdmin;password=fdfd;multipleactiveresultsets=True;connect timeout=30;encrypt=True;trustservercertificate=False;application name=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<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" />
<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=mydbstorage;AccountKey=7Ukljdslkjasdfjkdasfkj==" />
</appSettings>
<system.web>
<customErrors mode="Off" />
<roleManager
enabled="true"
cacheRolesInCookie="true" >
</roleManager>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" maxRequestLength="10240" executionTimeout="3600" />
<globalization culture="en-GB" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="10485760" />
</requestFiltering>
</security>
<modules>
<remove name="FormsAuthentication" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="PdfSharp" publicKeyToken="f94615aa0424f9eb" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.32.2608.0" newVersion="1.32.2608.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<location path="answers">
<system.web>
<authorization configSource="myadmin.config" />
</system.web>
</location>
<location path="audits">
<system.web>
<authorization configSource="myadmin.config" />
</system.web>
</location>
<location path="candidates">
<system.web>
<authorization configSource="myadmin.config" />
</system.web>
</location>
<location path="vCandidateTables">
<system.web>
<authorization configSource="members.config" />
</system.web>
</location>
<location path="documents">
<system.web>
<authorization configSource="members.config" />
</system.web>
</location>
<location path="companies">
<system.web>
<authorization configSource="myadmin.config" />
</system.web>
</location>
<location path="questions">
<system.web>
<authorization configSource="myadmin.config" />
</system.web>
</location>
<location path="users">
<system.web>
<authorization configSource="myadmin.config" />
</system.web>
</location>
</configuration>
更新我的错误出在角色管理器上——如果我禁用了它,问题就会消失……还有角色管理,但仍然!这是一个步骤……我的问题的答案是,我启用了
,因为我相信我是指ASP.NET Identity 2。它们不一样!启用了旧版本的身份管理然后
元素默认为localdb
。因此…这就是额外连接字符串的来源。下面是
在Azure的有效machine.config中的外观(请注意提供程序->connectionStringName
):
这是因为rolemanager用于旧形式的asp标识,而不是asp.NET标识2
(这是一个很小的问题,但我发现这个错误的方式只是通过源代码管理、重建和查看哪一个更改打破了它。)我的问题的答案是,我启用了
,因为我认为我引用的是ASP.NET Identity 2。它们不一样!启用了旧版本的Identity management,然后
元素默认为localdb
。因此…这就是额外连接字符串的来源rom。下面是Azure中的有效machine.config中的
的外观(注意提供者->连接字符串名称):
这是因为rolemanager用于旧形式的asp标识,而不是asp.NET标识2
(这是一个很小的问题,但我发现这个错误的方式只是通过源代码管理、重建和查看哪一个更改打破了它。)你的machine.config
中有什么?我认为Azure没有,是吗?它有,但这些都被剥离了。你能在这里发布你的web.config吗。这些是Visual Studio项目向导在创建新应用程序时设置的默认连接字符串项。它们可以隐藏在EntityFramework本身的配置部分中。确定吗。添加。还请注意,我已将范围缩小到启用角色管理器。我认为,如果使用迁移创建新数据库,它将在新位置创建角色管理所需的所有内容
<roleManager
enabled="false"
cacheRolesInCookie="false"
cookieName=".ASPXROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All"
defaultProvider="AspNetSqlRoleProvider"
createPersistentCookie="false"
maxCachedResults="25">
<providers>
<clear />
<add
connectionStringName="LocalSqlServer"
applicationName="/"
name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add
applicationName="/"
name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
<roleManager
enabled="true"
cacheRolesInCookie="true"
defaultProvider="OurSqlRoleProvider"
>
<providers>
<add
connectionStringName="DefaultConnection"
applicationName="/"
name="OurSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider" />
</providers>
</roleManager>