D
D
deyen2016-11-20 15:11:33
Debugging
deyen, 2016-11-20 15:11:33

How to debug Windows services in C sharp?

In general there are 2 functions:
public static void tolog(string text)
{
File.AppendAllText("N:\\logs\\test.txt", text);
}
public static string GetUID()
{
// read registry
RegistryKey currentUserKey = Registry.LocalMachine;
RegistryKey UidKey = currentUserKey.OpenSubKey("defined path");
string result = (string)UidKey.GetValue("Value");
UidKey.Close();
tolog(result);
return result;
}
why is the file log not created?
there is a directory, the service is started on behalf of the system (which is natural),
there are no restrictions on rights, you
need to track how it gets the value from the registry and write it to the log, but something is wrong

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Kuznetsov, 2016-11-21
@deyen

Build the service under debug. Then you can connect to it through the debugger when it is running as a service.
From VS running as system administrator, which is important.
Once you have connected, you only need to trigger the above logic. Well, set breakpoints in advance, of course.

D
Denis Velikanov, 2017-02-27
@rklimcorp

You have an M:N (many-to-many) relationship between the ITEMS and ATTR tables, so it is most logical to choose from the ATTR_ITEMS auxiliary table and link other tables to it.
That is, the main body of the request (before the WHERE clause) will be something like

SELECT *
FROM `attr_items` ai
inner join `items` i on ai.id_item = i.id
inner join `attr` a on ai.id_attr = a.id

It is not entirely clear how the value for a category is determined.
Let's say the category "Auto/Moto" has id = 2, then for the first part of the question:
SELECT *
FROM `attr_items` ai
inner join `items` i on ai.id_item = i.id
inner join `attr` a on ai.id_attr = a.id
WHERE
/* условие для категории */
(a.category_id = i.category and i.category = 2) and
/* условие для марки автомобиля */
(a.name = 'Марка' and ai.val = 'Audi') and
/* условие для модели автомобиля*/
(a.name = 'Модель' and ai.val = 'Audi А8')

for the second part of the question:
SELECT *
FROM `attr_items` ai
inner join `items` i on ai.id_item = i.id
inner join `attr` a on ai.id_attr = a.id
WHERE
/* условие для категории */
(a.category_id = i.category and i.category = 2) and
/* условие для марки автомобиля */
(a.name = 'Марка' and ai.val = 'Audi') and
/* условие для года выбуска автомобиля*/
(a.name = 'Годвыпуска' and ai.val BETWEEN 2005 and 2015)

Note that the ATTR_ITEMS.VAL field appears to be of the varchar data type, so BETWEEN to for the release year it may not be applicable in the way I indicated. You may need to use the LIKE construct.
PS In my opinion, such a database structure is suitable only for small amounts of data. But, unfortunately, it is often used in 1C-Bitrix in production, which leads to slowdowns.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question