The format of the initialization string does not match the specification starting at index 0

I am using Microsoft Enterprise Lip. I have this method for adding a resource to a website. I get this error down, I don’t think this is a permission problem, and really I don’t know how to solve it. How do I test connectionStrings and works fine

<connectionStrings> <add name="SiteSqlServer" connectionString="Data Source=.;Initial Catalog=databaseName;User ID=sa;Password=***"/> </connectionStrings> public static int Insert(Resoursce r) { Database objDB = new SqlDatabase("SiteSqlServer"); int val = 0; using (DbCommand cmd = objDB.GetStoredProcCommand("InsertResoursce")) { // OutParameter objDB.AddOutParameter(cmd,"@OutResoursceID",DbType.Int32,int.MaxValue); // iNParameter objDB.AddInParameter(cmd, "@ModuleId", DbType.Int32, r.ModuleId); objDB.AddInParameter(cmd, "@Summary", DbType.StringFixedLength, r.Summary); objDB.AddInParameter(cmd, "@PageId", DbType.StringFixedLength, r.PageID); objDB.AddInParameter(cmd, "@TypeId", DbType.Int32, r.TypeID); objDB.AddInParameter(cmd, "@UserID", DbType.Guid, r.UserID); objDB.AddInParameter(cmd, "@Enabled", DbType.Boolean, r.Enabled); objDB.AddInParameter(cmd, "@SafetyAlert", DbType.Boolean, r.SafetyAlert); objDB.AddInParameter(cmd, "@SaftyAlertText", DbType.StringFixedLength, r.SafetyAlertText); try { val = objDB.ExecuteNonQuery(cmd); if (val == 1) { return Convert.ToInt32(objDB.GetParameterValue(cmd, "@OutResoursceID")); } else { return -1; } } catch (Exception ex) { throw ex; } } 

Thrown System.ArgumentException. HResult = -2147024809
Message = Initialization string format does not match starting at index 0. Source = System.Data StackTrace: in System.Data.Common.DbConnectionOptions.GetKeyValuePair (string connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String & keyname, String & KeyValue) in System.Data.Common.DbConnectionOptions.ParseInternal (Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) in System.Data.Common.DbConnectionOptions..ctor (String connectionString, Hashtable syntax, BooleanulesOdb. Data.SqlClient.SqlConnectionString..ctor (String connectionString) in System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions (String connectionString, DbConnectionOptions previous) in System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGectionPbCeyDec yuch, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions & userConnectionOptions) in System.Data.SqlClient.SqlConnection.ConnectionString_Set (DbConnectionPoolKey key) in System.Data.SqlClient.SqlConnection.set_ConnectionCrect.Strement.Data (Data) ) in Microsoft.Practices.EnterpriseLibrary.Data.Database.GetNewOpenConnection () in Microsoft.Practices.EnterpriseLibrary.Data.Database.GetWrappedConnection () in Microsoft.Practices.EnterpriseLibrary.Data.Database.GetOpenConnection () in Microsoft.Practices. Data.Database.ExecuteNonQuery (DbCommand team) in Christoc.Modules.ResourceModule.App_Code.BOL.Resoursce.Insert (Resoursce r) in C: \ Inetpub \ Wwwroot \ Ideapark \ DesktopModules \ ResourceModule \ App_Code \ BOL \ Resoursce. 54 InnerException:

+6
source share
1 answer

This usually means that your connection string is not good. If you look at the stack trace, you will notice that this is an error when trying to interpret the connection string.

Check the connection string to make sure it is correct, or post it here for reference (but without any confidential information such as passwords;))

UPDATE

According to the SqlDatabase documentation, the SqlDatabase class accepts a connection string, not a connection string configuration key.

So,

 new SqlDatabase("SiteSqlServer"); 

Must be

 var connection = ConfigurationManager.ConnectionStrings["SiteSqlServer"]; Database objDB = new SqlDatabase(connection.ConnectionString); 

(for brevity, I missed some security code here)

+9
source

Source: https://habr.com/ru/post/943581/


All Articles