2017-07-14 37 views
1

我有一个C#.NET Web应用程序使用EF连接到SQL Server数据库,并且它引发'初始化字符串格式不符合规范开始索引0'错误。这只发生在我的远程服务器上,它在本地工作正常。很显然,我的连接字符串是不正确的,我的问题不是直接关于这个错误。抛出一个错误,包括连接字符串

我的应用程序有5个匹配5个SQL Server数据库的上下文,每个在我的web.config文件中都有一个连接字符串。我知道第一个上下文正在工作,但我不知道其他上下文中哪个是问题。 web.config中的5个连接字符串都非常相似,如果第一个(显然工作正常)工作,我不明白为什么不工作。所有5个连接字符串用于工作,发生了什么变化。

所以我想要更多的线索。

这里是我的YSOD我的堆栈跟踪:

[ArgumentException: Format of the initialization string does not conform to specification starting at index 0.] 
    System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +1739 
    System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +191 
    System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +136 
    System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +76 
    System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +35 
    System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +241 
    System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) +78 
    System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +116 
    System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +931 
    System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString(DbConnection connection, DbConnectionPropertyInterceptionContext`1 interceptionContext) +509 
    System.Data.Entity.Internal.LazyInternalConnection.Initialize() +77 
    System.Data.Entity.Internal.LazyInternalConnection.get_Connection() +16 
    System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo, Func`1 resolver) +508 
    System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase) +370 
    System.Data.Entity.MigrateDatabaseToLatestVersion`2.InitializeDatabase(TContext context) +140 
    System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +72 
    System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +483 
    System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +177 
    System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +274 
    System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +38 
    System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +77 
    System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +21 
    System.Data.Entity.Internal.Linq.InternalSet`1.Find(Object[] keyValues) +32 
    Argus.RdAP.GetCodeFromIndex(Int32 IndexNumber) +140 
(etc...) 

OK,这里是我的问题:这将是非常方便的,如果我能看到什么不好的连接字符串了。我有一个很好的想法,即代码中的问题在哪里开始(即在Argus.RdAP.GetCodeFromIndex中)。是否有一个尝试...赶上...抛出一段代码,将包含实际连接字符串在抛出的异常?

对不起,如果这是一个愚蠢的问题。另外 - 欢迎访问连接字符串或修复我的基础问题的替代建议。

+0

我基本上会阻止将连接字符串的内容写入异常(即日志文件/服务器/ ...)连接字符串可能包括密码等机密信息。 –

+0

我的连接字符串没有密码,这是一个非常临时的措施,但很棒,谢谢。 – Shewan

回答

0

最终我找到了答案!

try 
{ 
    // here was the method I suspected of causing the problem 
} 
catch 
{ 
    throw new Exception(ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString); 
}