As shown in my previous post QODBC/QODBC3 is not that good to work with databases. I have found a year old suggestion here to use ADODB for SQL Server. Can anyone give an example showing or suggest a link explaining How to connect, query and get result using ADODB.Connection in Qt?
You need to use QAxObject.
First you should take a look at:
QAxObject documentation: doc.qt.io/qt-5/qaxobject.html
Active X data object documentation: msdn.microsoft.com/en-us/library/windows/desktop/ms676795(v=vs.85).aspx
Here is a sample code to get you started:
// Create connection
QAxObject *connection = new QAxObject("ADODB.Connection");
connection->dynamicCall("Open(\"Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=Inaz;Data Source=SERVER02\")");
// Execute query and get recordset
QAxObject *recordSet = connection->querySubObject("Execute(\"select column01 from table01\")");
// Get fields
// or check https://msdn.microsoft.com/en-us/library/ms681510(v=vs.85).aspx to see what you can do with and how to use a recordset
QAxObject *fields = recordSet->querySubObject("Fields");
Note: You will need to call CoInitialize to use ADODB. However QGuiApplication and QApplication call it internally so you might not always need to make the call yourself.
Related
I have created a new index that is populated using an indexer. The indexer's datasource is a SQL view that has a Timestamp column of type datetime. Since we don't want a full reindexing each time the indexer runs, this column should be used to determine which data have changed since the last indexer run.
According to the documentation we need to create or update the datasource by setting the HighWatermarkColumnName and ODataType to the DataChangeDetectionPolicy object. The example in the documentation uses the REST API and there is also way to do it using the azure search portal directly.
However I want to do it using .netsdk and so far I haven't been able to do so. I am using Azure.Search.Documents(11.2.0 - beta.2). Here is the part of the code I use to create the datasource:
SearchIndexerDataSourceConnection CreateIndexerDataSource()
{
var ds = new SearchIndexerDataSourceConnection(DATASOURCE,
SearchIndexerDataSourceType.AzureSql,
this._datasourceConStringMaxEvents,
new SearchIndexerDataContainer(SQLVIEW));
//ds.DataChangeDetectionPolicy = new DataChangeDetectionPolicy();
return ds;
}
The commented code is what I tried to do to initialize the DataChangeDetectionPolicy but there is no ctor exposed. Am I missing something?
Thanks in advance.
Instead of using DataChangeDetectionPolicy, you will need to use HighWaterMarkChangeDetectionPolicy which is derived from DataChangeDetectionPolicy.
So your code would be something like:
ds.DataChangeDetectionPolicy = new HighWaterMarkChangeDetectionPolicy("Timestamp");
I need to support database logging.
For that I decided to use nlog because it brings database support.
But first of all I need to setup the configuration programatically.
As far as I understood it I have to set the layout for the target.
But the class "DatabaseTarget" does not have any property related to Layout :/.
var dbTarget = new DatabaseTarget();
dbTarget.ConnectionString = LogConnectionString;
dbTarget.CommandType = System.Data.CommandType.StoredProcedure;
dbTarget.CommandText = "exec dbo.InsertLog #level=${level}, #callSite=${callsite}, #message=${message}, #stackTrace=${stacktrace}, #machinename=${machinename}, #processname=${processname}";
Is the layout definition really necessary for the DatabaseTarget. If so how do I set it programatically?
Additionally I want to pass some information. But I am not sure how I can assign those informations for the procedure.
As far as I understood it I can assign those variables:
https://github.com/nlog/nlog/wiki/Layout-Renderers
But NLog support generic arguments with his Log Method. It looks like this:
_nLog.Log<AJourFaultLevel>(ConvertLogLevel(logEntry.Level), logEntry.Message, logEntry.Fault);
How can I assign the passed "logEntry.Fault" value for my stored procedure?
Best regards
Your current log-statement injects logEntry.Fault as parameter into string.Format(logEntry.Message, logEntry.Fault):
_nLog.Log<AJourFaultLevel>(ConvertLogLevel(logEntry.Level), logEntry.Message, logEntry.Fault);
If you are using NLog 4.5 then you can use structured-logging where you can name the parameter like this:
_nLog.Log<AJourFaultLevel>(ConvertLogLevel(logEntry.Level), "Fault occurred: {AJourFaultLevel}", logEntry.Fault);
Then you can access the named parameter using ${event-properties:item=}:
dbTarget.CommandText = "exec dbo.InsertLog #level=${level}, #callSite=${callsite}, #message=${message}, #stackTrace=${stacktrace}, #machinename=${machinename}, #processname=${processname}, #faultLevel=${event-properties:item=AJourFaultLevel}";
Having created a copy of an Access DB Backend in SQL Server, the Access Frontend has stopped showing the "Filter" list when the Filter button is pressed on the main form:
Before:
After:
I'm not sure what is causing this. In the old frontend I am opening the form like this:
Set rs = CurrentDb.OpenRecordset(sSQL)
Where sSQL is like:sSQL= "Select * from [EventReport]"
And in the new version I'm opening the form like this:
Set rs = CurrentDb.OpenRecordset(sSQL, dbOpenDynaset, dbFailOnError + dbSeeChanges)
I'm not sure if any of this is actually relevant to the issue, by any help is appreciated!
Tom
a bit more googling found the answer. In Access Options I needed to turn on the ODBC Fields in the Filter Lookup options for the Current Database
I've hit a problem with my database. The purpose of the section of my application is simple this; when a user marks an assignment of work complete, it will transfer one DataRow from "activeUnits" by using the "table.ImportRow" method to another table called "completedUnits" and then use the table adapter to update this change to the core database. However when testing this function the Dataset has completed the move of rows successfully internally, but upon using the TableAdapter.Update method the update of data to the database returns simply as "0" with no changes made or errors to lead.
Try
Dim activeRowMove As DataRow = Me.AssignmentDataSet.activeUnits.Rows(currentIndex)
Dim newMove As DataTable = Me.AssignmentDataSet.completedUnits
newMove.ImportRow(activeRowMove)
'UPDATE CHANGES
Me.Validate()
CompletedUnitsBindingSource.EndEdit()
Console.WriteLine(Me.CompletedUnitsTableAdapter.Update(Me.AssignmentDataSet.completedUnits))
activeUnitsTitle.Text = ("Assignment Completed!")
Catch ex As Exception
Console.WriteLine("Failed to update new table: " & ex.ToString)
activeUnitsTitle.Text = ("Failed to save!")
End Try
Is there somewhere in my code which I've simply done wrong, or any better or efficient way of moving a datarow is appreciated!
My database is not copied in my project's bin folder and every update goes to one central location.
If needed the following link is two screenshots of my current layout and data - here.
From MSDN:
Calling ImportRow preserves the existing DataRowState along with other values in the row
So, if the DataRowState in your "from" table is Unchanged, then its state will remained Unchanged in the "to" table, and it will not get saved.
Make sure to change the DataRowState of the newly imported row to Added
Cheers
I am using the latest version of the MiniProfiler, everything is setup and working as I would expect. My only issue is that SqlParameters are not being displayed.
For example, I am running a stored procedure:-
var cmd = dbcon.CreateCommand();
cmd.CommandText = "USP_Admin_Subscription_List";
cmd.CommandType = CommandType.StoredProcedure;
// parameters
cmd.Parameters.Add(new SqlParameter("#UserRef", SqlDbType.NVarChar) { Value = customerRef });
When this executes I see the SQL in the MiniProfiler display but I do not see the Parameter #UserRef nor it's value.
Is this possible? It would be great to see the value so I can ensure the correct value is being passed.
I am using MVC 3
Any advice would be welcomed.
Cheers,
J
Old questions, but just in case anyone else is looking for the answer to this:
The sample code has:
// different RDBMS have different ways of declaring sql parameters - SQLite can understand inline sql parameters just fine
// by default, sql parameters won't be displayed
MiniProfiler.Settings.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();
You need to change it to:
MiniProfiler.Settings.SqlFormatter = new StackExchange.Profiling.SqlFormatters.SqlServerFormatter();
And your parameters will appear.