Wednesday, April 13, 2011

Auto-hide panel in QT or WxWidgets

I am looking to find a way to have a docked panel that would be similar to the panels within visual studio.

Essentially a panel that can be set to auto hide or can be pinned open.

Possibly this question was a bit vague. What I am looking for is essentially this product

Please leave a comment if I am missing details as I would like this question solved. I have searched google a fair bit and have not been able to find a possible solution. If worse comes to worse I will end up using a shortcut to hide and unhide the side panel.

From stackoverflow
  • check out the AUI demo in wxWidgets.

    Victor T. : @braindead the wxAUI doesn't have that auto-hide/pinning feature the OP is looking for.
  • Qt4 has QDockWidget class, maybe that's what you're looking for?

    http://doc.trolltech.com/4.5/qdockwidget.html

  • Qt sadly doesn't support this. I've bugged them and others but got no word. I'm writing my own to doing this.

IIS Hang Troubleshooting

I'm running a website on IIS 6 (Windows Server 2003) that hangs occasionally.

Timeline:

Released to the wild, website ran fine for 3 days.

Website hangs on every request until the website is stopped and started.

Website runs for 2 weeks with no problem.

Website hangs on every request until site is restarted.

We see a few application log entries before hang starts: Faulting application w3wp.exe, faulting module unknown, version 0.0.0.0 fault address -------.

The application installed on the website is written in .Net 2.0.

Can anyone please guide me on troubleshooting this issue? Thanks!

From stackoverflow
  • Your best bet might be to use adplus to capture a memory dump of the hanging w3wp process, and then use windbg + the sos extension to try to determine the cause of the hang.

    You can get adplus and Windbg here: http://www.microsoft.com/whdc/devtools/debugging/default.mspx

    Also, Tess Ferrandez' blog is an absolute goldmine of information on learning how to analyze memory dumps with Windbg. She even has a set of labs you can go through targeted toward specific scenarios.

    http://blogs.msdn.com/tess/default.aspx

  • There are many reasons why this could happen. A couple of years ago, I had this happen on web project in production, and it took a call to Microsoft to fix it. I wish I could give you specific details but this is what I remember.

    .NET caches the folders in your web application. There is a registry key on the server (cannot remember where ) that sets a folder limit (believe it or not). The limit was set to 150 folders by default. If you had more than this many folders in your web application, and you tried to access the 151st folder, it would crash IIS.

    Yes this sounds crazy but trust me, I spent weeks with Microsoft until we found out the cause of the crash. The answer at the time was to up the limit in the registry and reboot the server. This was a couple of years ago, and I hope that this was fixed in later updates, but I offer this to you just in case you are using an older version of Server 2003.

    I am sorry I cannot provide more specific details, but I just want to let you know my experiences just in case this sounds like your issue.

  • make sure IIS is set to be able to recycle its process automaticly, might help to fix the issue if it is a memory leak. (well ok cope with the problem not fix)

    My advice is to give you app its own application pool, so you are 100% sure that its the appication you think pulling the server down, what dose the application log say when this happens?

    From the information you have given it sounds like its a memory leak or open db connection / thread issue.

    P.s If you are using N2 there was a known issue that when IIS recycled it wouldnt come back up.

Linq: IsNot in Object collection

Dim goodCustObjList As New List(Of CustomerObj)
goodCustObjList = DataBLLModule.GetCustomerRecordList(String.Empty)
Dim custList = From t In goodCustObjList _ 
               Where t.ID.ToString() IsNot Guid.Empty.ToString() _
               Select t

I have a list of CustomerObj and if the ID (GUID) is not empty then i want to select that object. I did a similar query but the condition is on another object's property (integer) that match if it is 1 or 2 then select it.

Can someone point out what i'm doing wrong on the above linq statement? if you going to test an condition in linq. Isn't IsNot is the correct statement to test that condition?

Jack

From stackoverflow
  • "IsNot" in VB means to test whether two object references point to different objects. I'm not sure why you are getting this for this particular syntax. Can you post the definition of CustomerObj?

    What you really want to be doing though is comparing the .ID property directly.

    Where t.Id <> Guid.Empty
    

    This is the most reliable way of comparing GUID values. Comparing their String values is much slower and can be thrown off if you accidentally do a case sensitive comparison.

    Tom Anderson : Quite right on that comment, this is the proper way.
    Jack : that's it. Thank for the help

In XSLT, how can you get the file creation/modification date of the XML file?

I would like to know the file creation/modification date of the XML file currently being processed by my XSLT code.

I am processing an XML file and producing an HTML report. I'd like to include the date of the source XML file in the HTML report.

Note: I am using C# .NET 2008 and using the built-in XslCompiledTransform class. I have since found a solution (separate answer) using input from other answers here. Thanks!

From stackoverflow
  • The creation/modification date must be written into the XML file, otherwise you cannot find it out, unless you communicate somehow with the filesystem.

    This question is somewhat related: xslt-how-to-get-file-names-from-a-certain-directory

  • The only things that XSLT has access to are nodes of the source tree, nodes in documents read in via the document() function, nodes in the XSLT template itself (again via the document() function), and values passed in to the transform as arguments.

    So if you want the filename and its creation/modification date to be available to your transform, you have to put them in one of those places.

    It's possible to implement XSLT extension methods to do this, depending on what platform you're using, but that would be my last choice.

  • After suggestions from Kaarel and Robert, I was able to reach the following solution:

    Get the file modification date in C# and pass it to the XSLT processor as follows:

    XmlTextWriter tw = new XmlTextWriter(htmlPath, null);
    tw.Formatting = Formatting.Indented;
    tw.Indentation = 4;
    
    XsltArgumentList args = new XsltArgumentList();
    FileInfo fi = new FileInfo(xmlPath);
    args.AddParam("FileDate", string.Empty,
       fi.LastWriteTime.Date.ToShortDateString());
    
    XslCompiledTransform xslt = new XslCompiledTransform();
    xslt.Load(xsltPath);
    xslt.Transform(xmlPath, args, tw);
    tw.Close();
    

    Then in the XSLT code, define and access that argument as a param as follows:

    <xsl:param name="FileDate"/>
    
    <xsl:text>Revision Date: </xsl:text>
    <xsl:value-of select="$FileDate"/>
    

Dynamically adding user controls registered in web.config‏

So I'm working on a project that has all its user controls registered in its web.config file (which seems very clean and tidy)

So far so good (here comes the problem) however I'm trying to dynamically create and add user controls to a page. These user controls fire events that need handling.

Ordinarily that wouldn't be a problem: You just register the control in the page, load the control, cast it to the correct type, and assign the event handlers, add it to the page, sit back and let the magic happen, easy peasy.

But I can't reference the control's type when the control is registered in the web.config, which means no cast, which means no event handling!

Weirdly you can reference the type if you add the usercontrol to the page at design time!

There must be a way round this (without having to register the control on the page, or add a control at design time), what on earth am I missing?

From stackoverflow
  • By saying : "you can reference the type if you add the usercontrol to the page at design time"

    Do you mean it adds an <%@ Register %> Directive at the top of the page ?

    Or maybe, it adds a using / Imports (depending on you using c# / vb.net) clause in your source document ?

    Because, to be able to cast to your control type, you normally need to import the namespace in the codebind. Maybe this is just what is missing.

    Wilfred Knievel : No that's the weird thing, the registration is done in the web.config () so there isn't any need for <%@ Register %> directive on the page. If you drag your user control on the page the everything just starts working (doesn't add a <%@ Register %> or an includes)
  • The <controls> section in web.config and the <%@ Register %> directive are the same thing (with the small exception that entries in web.config apply to the whole application). They allow you to add design-time controls to a web form.

    If you want to add controls to a page dynamically, use the LoadControl function to get an instance of your control. Given a control with a class name of "Header", the following will load a control, set a property, and add the control to the form named, "form1":

        Dim head As Header = LoadControl("~/Controls/Header.ascx")
        head.Text = "Some text..."
        Me.form1.Controls.Add(head)
    
    Wilfred Knievel : That's exactly what I expected, but I get "The type or namespace name 'Header' could not be found (are you missing a using directive or an assembly reference?)" (the weird thing is if I add the tag for a header control to the page [just the ] it will work fine!)
  • It's been a while, but I think I've seen this type of behavior in ASP.NET when a project is a Web Site and not the Web Application. As far as I remember, the Web Site compiles each page into its own assembly and with no common name space and regardless of config requires the <%@ Register %> directive. If you don't, you get the exact error of missing an assembly reference.

    I would have to test to be sure...

    Martin : You're right about the website compiling each page into it's own assembly. If you register controls in the web.config, it should be fine. However, maybe the controls have to be defined in a separate assembly for it to work. At work, we use telerik's controls in a website project and it works fine.
    Wilfred Knievel : You're absolutely right, just did a quick test and it worked fine in a Web application and failed miserably in a website. Thanks for that!
  • I am trying to do the same thing also. I want to be able to do something like:

    Dim head As Header = LoadControl("MyHeaderTagPrefix", "MyHeaderTagName")
    head.Text = "Some text..."
    Me.form1.Controls.Add(head)

    I would expect to be able to retriev the control using those 2 values at runtime (aka Dynamically).

    Any ideas?

How to find out user name and machine name to access to SQL server

My work company has a MSSQL server 2005. I have two questions about finding out current log user and any way to send out a warning message:

First question is if there is any T-SQL or SP available to find out current login user name and machine name. If the user is using SQL server sa name to remotely access to SQL server, is there any way to find out that user's windows name (the name to log to the windows)?

My next question is that if I can get the user name or id, is there any way to send out a warning message such as "currently SQL server is clean up or backup, please do not log in at this time". I guess it may be difficult. I may have to send an email out to the user.

The SQL server is only accessible in the company. The SQL server has a list of users as login users: windows users, SQL users and sa.

From stackoverflow
  • SELECT SUSER_SNAME(), HOST_NAME()

    I the connection is "sa" (or any other SQL login) then you can't find the domain/windows user name. SQL Server only knows it's "sa".

    HOST_NAME may not be reliable either, it can be set in the connection string. MS Access for example does not support this.

    You could backtrack via client_net_address in sys.dm_exec_connections and match MAC address to IP and find out who is logged on...

    John Sansom : +1:Well thought out answer.
  • An easy way to find out both host and user is

    EXEC sp_who2;
    

    where you get some other information that can be good to know, as if the user is active and so on... It does not resolve the issues that gbn announced.

  • For a more visual representation of grabbing a list of users and what Databases they are in open up Microsoft SQL Server Management Studio. In there you can click on the Management folder then Double Click on Activity Monitor.

    This will give you a graphic display similar to running sp_who in a query. The user tab will give you a clue to what type of account they have.

    You can also run quick filter on that list to narrow down your search. e.g. via a database.

  • Thanks for all your suggestions first. I tried all the methods and I think Joakim Backman's method meet my need. Here is summary of what I find out.

    • Query of sys.syslogins only list login information. The accdate does not give the current login user timestamp. I tried to login from another application to my SQL and this query does not list the login.
    • SELECT SUER_SNAME(), HOST_NAME() only list one user on SQL server. For example, I login in as my name to SQL server. The result this query only list my name and machine name. This query does not list current user on the SQL server.
    • exec sp_who2 lists information I need. It lists current user name machine name, active status, db name users access, and command used.

    In order to get the information I use in SP, I have to filter and join the information with other tables such as emails. Here is the codes I use:

    DECLARE @retTable TABLE (
     SPID int not null
     , Status varchar (255) not null
     , Login varchar (255) not null
     , HostName varchar (255) not null
     , BlkBy varchar(10) not null
     , DBName varchar (255) null
     , Command varchar (255) not null
     , CPUTime int not null
     , DiskIO int not null
     , LastBatch varchar (255) not null
     , ProgramName varchar (255) null
     , SPID2 int not null
     , REQUESTID INT
    )  
    
    INSERT INTO @retTable EXEC sp_who2  
    
    SELECT Status, Login, HostName, DBName, Command, CPUTime, ProgramName -- *
      FROM @retTable
      --WHERE Login not like 'sa%' -- if not intereted in sa
      ORDER BY Login, HostName
    
  • I have use the above sp that recommend by David. It works great for my development Database, but can't be run at Live Database.

    Is this due to access rights or security issues?

Extension of question many to many relationships in same table.

I got a single table and it contain 4 fields

Id|Hospital|   Doctor|patient

1     A        D1      P11

2     B        D6      P61

3     A        D2      P21

4     A        D1      P12

5     B        D7      P71

6     B        D6      P62

7     B        D6      P63

Doctors are unique to the Hospital. They don't work in other hospitals. Patients are unique to the doctor they don't visit any other doctor. Each hospital is having multiple Doctors.

If you observe there are multiple patients for each doctor.

Now the question is: How can I get "only one patient" related to the each doctor. It can be any patient from the record.

I am looking forward to see some thing like this

 Hospital Doctor Patient
  A       D1      P11

  A       D2      P21

  B       D6      P61

  B       D7      P71

I got the answer like select Hospital,doctor, max(patient) from table GROUP BY Hospital,Doctor ORDER BY Hospital,Doctor;

How to get the id also which is unique from the above table like.

id Hospital Doctor Patient
 1   A       D1      P11

 3   A       D2      P21

 2   B       D6      P61

 5   B       D7      P71

I am very sorry to repost this question.

From stackoverflow
  • Try something like:

    select Id,Hospital,Doctor,Patient
      from table
      where Id in (select max(t.Id) from table t group by t.Hospital,t.Doctor)
      order by Hospital,Doctor;
    
    Giridhar : Your answer is accurate sweet and short.Thank you
  • SELECT  m.*
    FROM    (
            SELECT  (
                    SELECT  id
                    FROM    mytable mi
                    WHERE   mi.hospital = md.hospital
                            AND mi.doctor = md.doctor
                    LIMIT 1
                    ) AS first_patient
            FROM    (
                    SELECT  DISTINCT hospital, doctor
                    FROM    mytable
                    ) md
            ) mo, mytable m
    WHERE   m.id = mo.first_patient
    
    Giridhar : This script says that right paranthsis is missing at SELECT ( SELECT id FROM mytable mi WHERE mi.hospital = md.hospital AND mi.doctor = md.doctor LIMIT 1 ) AS first_patient
  • You might look at breaking things into three tables: Hospitals (with Primary Key id, and the Hospital field), Doctors (with someother PK, a Foreign Key of Hospitals, and the Doctor field) and Patients (with someother PK, a Foreign Key of Doctors, and the Patient field). Then your statement would look something like:

    SELECT H.Id, H.Hospital, D.Doctor, Max(P.Patient)
    FROM Hospitals H
    INNER JOIN Doctors D ON H.Hospital = D.Hospital
    INNER JOIN Patients P ON D.Doctor = P.Doctor
    ORDER BY Hospital, Doctor
    
    Giridhar : I dont have the control on table.
    Lance Roberts : OK, then you'll have to use the other answers.