是否可以将ConnectionStrings和mailSettings与web.config分开?
由于开发和测试,开发环境对连接字符串和smtp邮件具有不同的IP地址.我们不想使用实时机器和实时IP地址进行测试和开发.
可能吗?
我们目前在开发环境中遇到一个相当麻烦的问题,有以下消息......
A connection was successfully established with the server,
but then an error occurred during the pre-login handshake.
(provider: SSL Provider, error: 0 - The certificate's CN
name does not match the passed value.)
Run Code Online (Sandbox Code Playgroud)
...解决此问题的普遍接受的智慧是将连接的TrustServerCertificate部分设置为True.但是,这不能可靠或一致地工作.
此特定错误发生在许多实例中,例如在Azure模拟器中测试我们的WCF服务,与实时/托管SQL Azure实例进行通信,甚至使用SQL Management Studio.我们发现的唯一共同点是,只有当我们直接连接到SQL Azure而不是托管和Azure直接与SQL Azure(它确实有效)对话时才会出现这种情况.
我已经尝试了许多策略来解决这个问题(比如这里详述的那个),即相信它是连接相关的并且删除了对连接字符串的池化和其他修改.但是,没有一个是决定性的,更令人恼火的是,这个错误是间歇性的,并且会在神奇地解决自己之前在短时间内阻止访问.
我已经消除的其他因素.
有没有其他人遇到此问题或有任何建议?
我想将ConnectionTimeout设置为默认值以外的值,即15秒.我继承了一些使用EntityFramework的代码,app.config看起来像这样:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS; Integrated Security=True; ConnectionTimeout=30; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; ConnectionTimeout=30; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Run Code Online (Sandbox Code Playgroud)
我是那个为了让事情发挥作用而添加了sectino的人.我可以告诉它在设置断点时无效:
var adapter = (IObjectContextAdapter) this;
var objectContext = adapter.ObjectContext;
objectContext.CommandTimeout = CommandTimeoutSeconds;
int test = objectContext.Connection.ConnectionTimeout;
Run Code Online (Sandbox Code Playgroud)
测试始终是15.发生了什么?有人能告诉我如何设置ConnectionTimeout吗?我已经尝试过"ConnectionTimeout"和"Connection Timeout",即没有空间与空间.
有人能帮我吗?我把头发拉了出来.我确定这是一个简单的修复!戴夫
附加信息.回应评论,这是我的DbContext派生类...
public class SessionDataContext : DbContext
{
// Command timeout (seconds)
private const int CommandTimeoutSeconds = 30;
/// <summary> …Run Code Online (Sandbox Code Playgroud) 我在C#应用程序中使用Entity Framework 6,它完美地运行.创建Model时,将生成app.config并具有所有必需的配置.现在我不喜欢app.config中的东西,所以我使用连接字符串构建器.我成功地删除了app.config文件中的所有内容,除了以下内容:
<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>
Run Code Online (Sandbox Code Playgroud)
如果我删除它,它不起作用.那么如何将该配置转换为c#代码?我该怎么办?我查看了基于代码的配置(http://msdn.microsoft.com/en-us/data/jj680699)但是,它没有帮助.
我创建连接字符串的部分类看起来像这样:
public partial class LogEntities
{
public LogEntities(string serverName)
: base(GetConnectionString(serverName))
{
}
public static string GetConnectionString(string serverName)
{
// Specify the provider name, server and database.
const string databaseName = "_LOG";
// Initialize the connection string builder for the underlying provider.
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder
{
DataSource = serverName,
InitialCatalog = databaseName,
IntegratedSecurity = true,
MultipleActiveResultSets = true
}; …Run Code Online (Sandbox Code Playgroud) 如何将CommandTimeout添加到web.config中的连接字符串?
我试过了:
<add name="ConnectionString" connectionString="Data Source=;Initial Catalog=;Persist Security Info=True;User ID=sa;Password=sa@123;Connect Timeout=200" providerName="System.Data.SqlClient"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
还有这个:
<add name="MyProject.ConnectionString"
connectionString="Data Source=127.0.0.1;Initial Catalog=MyDB;Persist Security Info=True;CommandTimeout=60;User ID=sa;Password=saPassw0rd"
providerName="System.Data.SqlClient" />
Run Code Online (Sandbox Code Playgroud)
但它并没有为我工作.
谢谢
对于专用服务器,最好将连接字符串存储在web.config或machine.config中吗?每种方法的优点和缺点是什么?
谢谢
编辑:我关注这里的安全性,所以问题是哪种方法更安全.
我有两个开发团队,来自不同的团队.
有没有办法设置别名,以便两个组编码相同的名称?现在我们正在进行一场连接字符串战争,因为B组改变(本地),./DEVA组再次改变它?
sql-server connection-string visual-studio-2010 sql-server-2008 entity-framework-4
我需要知道在VB.NET中为WinForms应用程序存储SQL服务器连接字符串的常用方法是什么.
我搜索了网,我找到了以下每个问题的答案:
我想要一个完整的答案,如何安全地存储VB.NET中的连接字符串app.config(或者settings.settings如果它更好).
是app.config对的地方吗?我可以加密这些值吗?
我在azurewebsites上有一个简单的mvc网站(使用VS互联网模板),与同一数据中心的SQL Azure数据库通信.此时数据库只是用于内置的SimpleMembership Provider.我已经从默认的App_Data mdf文件切换到Azure SQL.它工作正常,但有时一段时间后,它会给:
建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称是否正确,以及SQL Server是否配置为允许远程连接.(提供程序:SQL网络接口,错误:26 - 查找指定的服务器/实例时出错)
留言很长:
SQLExpress数据库文件自动创建错误:
连接字符串使用应用程序的App_Data目录中的数据库位置指定本地Sql Server Express实例.提供程序尝试自动创建应用程序服务数据库,因为提供程序确定数据库不存在.要成功检查应用程序服务数据库是否存在并自动创建应用程序服务数据库,必须满足以下配置要求:
但我没有使用SQL Server Express的连接字符串!
立即重新启动网站不会删除错误.
没有改变任何东西并在15分钟后重新启动网站给出:
502 - Web服务器在充当网关或代理服务器时收到无效响应.
您正在查找的页面存在问题,无法显示.当Web服务器(充当网关或代理)与上游内容服务器联系时,它从内容服务器收到无效响应.
以前,我可以通过从VS重新发布将网站恢复到正常工作状态.但是在过去的一个小时里,我尝试过并尝试过,我无法让网站再次运行.
SQL Server Express真的有什么问题?
我的连接字符串部分包含:
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=tcp:sabl6h4---.database.windows.net,1433;Database=MVC;User ID=test@sabl6h4---;Password=----;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient" />
<add name="Entities" connectionString="metadata=res://*/Data.Model1.csdl|res://*/Data.Model1.ssdl|res://*/Data.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=sabl6h4---.database.windows.net;initial catalog=MVC;user id=test;password=----;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
为了确保,我将sabl6h4---.database.windows.net复制并粘贴到SSMS中并使用登录测试进行连接,并且没有问题地打开了数据库.
一天后:我创建了一个新的azurewebsite并发布了完全相同的项目和相同的web.config.它没有问题,工作正常.几分钟后,发生了完全相同的错误!
再过三个小时:去吃午饭,回来,点击浏览器刷新按钮,网站再次启动.我确信有人在后端的设置中鬼混.
asp.net-mvc entity-framework connection-string azure-web-roles azure-sql-database
我有一个运行n Azure的站点,它使用EF Database First模型.
如果我在web.config中嵌入连接字符串并且部署all是美好的.
<add name="MyEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string='Data Source=my.database.windows.net;Initial Catalog=myTest_DB;User ID=***;Password=***; MultipleActiveResultSets=False'" providerName="System.Data.EntityClient"/>
Run Code Online (Sandbox Code Playgroud)
但是,我不希望web.config中的连接字符串,因为它包含凭据.
所以我将它移动到Azure Properties中的连接字符串区域.
我遇到的第一个问题是获取元数据无效关键字错误
我通过将类型从SQL数据库更改为自定义来解决这个问题.
但是,我现在收到此错误:
应用程序配置文件中的连接字符串"MyEntities"不包含必需的providerName属性."
我已经在网上搜索并尝试了很多连接字符串,但还没找到正确的连接字符串.
注意:我想我可以将它设置为应用程序设置并将字符串的初始化移动到代码,但即使只是为了好奇,我想知道如何通过门户网站进行操作.
entity-framework connection-string azure azure-management azure-sql-database
azure ×2
connection ×2
web-config ×2
.net ×1
asp.net ×1
asp.net-mvc ×1
c# ×1
encryption ×1
security ×1
sql-server ×1
timeout ×1
vb.net ×1