VistaDB Support Center

Start a new topic

Using Vistadb5 and NLog 4

 Hi,


I'm trying to create some logging using NLog and a VistaDB5 database.


Can someone help me with the required connection string for use in NLog.


        string path = Path.Combine(dataDir, "MCLog.vdb5");


         VistaDBConnectionStringBuilder connStringBuilder = new VistaDBConnectionStringBuilder();
         connStringBuilder.DataSource = "MCLog.vdb5";
         connStringBuilder.Password = "Galwaypipe001";
         connStringBuilder.DataSource = path;
         connStringBuilder.Pooling = false;
         connStringBuilder.OpenMode = VistaDB.VistaDBDatabaseOpenMode.NonexclusiveReadWrite;


         string connString = string.Format("'{0}';Pooling=False;Open Mode=NonExclusiveReadWrite;Password=Galwaypipe001", path);
         DatabaseTarget dbt = new DatabaseTarget();
         dbt.Name = "NLog Database";
         dbt.ConnectionString = path; // connString; // connStringBuilder.ConnectionString; // connString;
         dbt.DBProvider = ****



At present I'm getting the following error from NLog:


2016-10-22 10:06:51.3735 Error Error when writing to database. Exception: System.ArgumentException: Keyword not supported: ''c:\programdata\aquarius communications\mycourts\resources\mclog.vdb5';pooling'.
  at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
  at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
  at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
  at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
  at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
  at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
  at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
  at NLog.Targets.DatabaseTarget.OpenConnection(String connectionString)
  at NLog.Targets.DatabaseTarget.EnsureConnectionOpen(String connectionString)
  at NLog.Targets.DatabaseTarget.WriteEventToDatabase(LogEventInfo logEvent)
  at NLog.Targets.DatabaseTarget.Write(LogEventInfo logEvent)



OR

 

2016-10-22 10:13:02.6354 Error Error when writing to database. Exception: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
  at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
  at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
  at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
  at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
  at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
  at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
  at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
  at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
  at NLog.Targets.DatabaseTarget.OpenConnection(String connectionString)
  at NLog.Targets.DatabaseTarget.EnsureConnectionOpen(String connectionString)
  at NLog.Targets.DatabaseTarget.WriteEventToDatabase(LogEventInfo logEvent)
  at NLog.Targets.DatabaseTarget.Write(LogEventInfo logEvent)




 

				VistaDBConnectionStringBuilder connStringBuilder = new VistaDBConnectionStringBuilder();
				connStringBuilder.Password = "****";
				connStringBuilder.DataSource = path;
				connStringBuilder.Pooling = false;
				connStringBuilder.OpenMode = VistaDB.VistaDBDatabaseOpenMode.NonexclusiveReadWrite;


				string connString = string.Format("'{0}';Pooling=False;Open Mode=NonExclusiveReadWrite;Password=***, path);

				DatabaseTarget dbt = new DatabaseTarget();
				dbt.Name = "NLog Database";
				dbt.DBProvider = "VistaDB.Provider.VistaDBConnection, VistaDB.5.NET40,  Version=5.0.0.0, Culture=neutral, PublicKeyToken=dfc935afe2125461";
				dbt.ConnectionString = connStringBuilder.ConnectionString;

 

 

				VistaDBConnectionStringBuilder connStringBuilder = new VistaDBConnectionStringBuilder();
				connStringBuilder.Password = "****";
				connStringBuilder.DataSource = path;
				connStringBuilder.Pooling = false;
				connStringBuilder.OpenMode = VistaDB.VistaDBDatabaseOpenMode.NonexclusiveReadWrite;


				string connString = string.Format("'{0}';Pooling=False;Open Mode=NonExclusiveReadWrite;Password=***, path);

				DatabaseTarget dbt = new DatabaseTarget();
				dbt.Name = "NLog Database";
				dbt.DBProvider = "VistaDB.Provider.VistaDBConnection, VistaDB.5.NET40,  Version=5.0.0.0, Culture=neutral, PublicKeyToken=dfc935afe2125461";
				dbt.ConnectionString = connStringBuilder.ConnectionString;

 

Thanks Rob,

After much trial and error I agree you are spot on again :-)


 

 


It may be complaining that the connection string doesn't have Data Source= before the path, so it's trying to parse the path as a property keyword and it, of course, isn't recognized as one.


For NLog to use a VistaDB database it also probably needs to be told the dbt.DBProvider matching the provider name in your config (typically "System.Data.VistaDB5") to use it as a generic ADO.NET provider.

Login to post a comment