Friday, February 11, 2011

Excel automation via OLE - suppressing / catching dialog box errors?

I refresh Excel 2007 data connections via a C# program and OLE. Most of the work is done by a single Workbooks.RefreshAll() statement.

As is the nature of refreshing spreadsheets, various things can go wrong. During the refresh process, the program can give dialog box error messages about "Data cannot be read from file '|'", and a message about "Overlapping pivottable reports". Both of these are fatal, and I should be able to catch these errors, and exit my program with an error.

Unfortunately, I don't seem to be able to catch these problems, and instead my automated program sits until I come along and hit enter on the dialog.

Does anyone know if it's possible to programmatically catch the errors shown in excel dialog boxes, instead of having them displayed to the user?

  • Your best bet is to set the Application.DisplayAlerts property to False. That is, assuming that your Excel.Application object variable is named "xlApp", all you'd have to do is the following:

    xlApp.DisplayAlerts = false;
    

    Note that this will cause the default response to be taken for each dialog box, which is normally what you would want. (There's no good way around this. Leaving DisplayAlerts = True and using SendKeys might be your only other option, but would be ugly and very error prone.)

    Since you are making this call via OLE Automation, this call is cross-process, and, therefore, the DisplayAlerts setting will persist until you change it. (If called in-process, via VBA, it is switches back to to true automatically when the routine completes. The same behavior probably applies for a VB.NET or C# add-in called via a CommandBar or Ribbon control, but one would need to test to be certain.)

What would you recommend as the best free online resource / tutorial to learn Agile Software Development methods?

I'm trying to learn Agile Software Development principles in a hurry and don't have time to wait for a book to arrive.

What would you recommend as the best free online tutorial on Agile Development methodology?

Edit: I agree with the answers that learning things in a hurry is not the way to go about it but as one poster guessed, I'm trying to get an overview of the topic for an interview.

  • http://en.wikipedia.org/wiki/Agile_software_development

    From Bob Dizzle
  • XP and scrum are decent places to start.

  • Jim Shore's Blog: http://jamesshore.com/Blog/

    But after reading it you will want to buy his book: http://jamesshore.com/Agile-Book/

  • I think you have bigger problems then needing to learn agile development, generally learning something vital in a short amount of time is going to cause you more problems then it is worth. You should take the time and LEARN it good.

    Bob Dizzle : yeah learn it good
    From Unkwntech
  • I know this isn't going to be what you want, but...

    I am personally of the opinion that you can't really learn good software development principles until you see bad ideas crash and burn. I spent a year as the lead developer on a project that...shall we say, could have been better-managed. I learned a LOT from it, both about my own practices and about what generally does and doesn't going to work.

    From chessguy
  • I assume you are looking for an overview for a job interview or something rather than actually trying to bring a development group up to speed in a few days.

    You might check C2, IIRC they were the ones that originated a lot of the agile stuff--the first agile wiki (the first wiki possibly), they are still up and still maintained.

    http://c2.com/cgi/wiki?ExtremeProgrammingRoadmap

    Good luck

    From Bill K
  • I've found Steve McConnell's Construx Software website to be a great resource, with lots of agile information. It's a fun place to spend some time browsing white papers.

  • I would heartily recommend reading Scrum and XP from the trenches. Its very hands on and gives good pointers on how to start implementing scrum in the organization and outlines both methodologies and tools in an easy to read way.

    Its a 140 page document, but it takes just a few hours to read.

    From Soraz

How did you find your "dream job" (or great place to work)?

I'm a senior developer and consider myself very good at what I do. I have high expectations for how I believe software should be developed. I'm having a hard time finding a place to work that shares a similar view on the software development process.

Here's my modified version of The Joel Test that I ask potential employers during an interview.

  • How do you determine the requirements for your system?
    • How do you document these requirements?
    • How are they prioritized?
    • What does your schedule typically look like?
  • Do you practice "test first" development?
  • Can you "build" in one step?
  • Do you build (and run automated tests) daily?
  • Do you use source control?
  • How do you manage releases?
  • Do you have a bug database?

I find it surprising that many companies never speak to their users to determine future requirements, have no automated tests, do not use source control, cannot build their systems without an IDE, and do not manage bugs or releases. Further many of these organizations don't realize that they have a problem, and therefore are not interested in implementing them (one place even commented "Hey, We're process lite!)

My questions are:

  1. How do you identify the "good" places to work (i.e. the places I should be focused on getting hired at)? To this point, my network has been of little help here.
  2. Are my standards too high? Do organizations that practice development in the way I'm describing actually exist? I've developed this list by reading and listening to people like Spolsky, Fowler, and the Poppendiecks so I'm assume their writing are at least in part based in reality.

Thanks!

  • I'd add that you have to believe in the company's product(s).

    If you don't, it doesn't matter how "good" the place might be.

    From warren
  • If you can't find such a company in your area, maybe you could consider starting your own. You already know that you'll be better than the local competition!

    Paul Batum : What if you dislike business? It is a bit naive to believe that good engineering practice is the only thing that makes a company successful - there is much more to it than that.
    harriyott : Yes, of course. I don't believe that it's the only thing, which I why I used the words "maybe", "could" and "consider".
    Paul Batum : I'm in a hair splitting mood. You state "you already know you'll be better than the local competition". This is the part i was disagreeing with.
    From harriyott
  • While I certainly dont want to work at a shop that hasn't the slightest respect for programming and throws standards and best-practices into the abyss, my dream job is dictated more by the work I am doing:

    1. Am I working with interesting technologies?
    2. Am I enthusiastic about the product?
    3. Am I going to want to go to work when I wake up?
    4. At the end of the day, will I be proud of my work and my accomplishments?
    NoProblemBabe : Well, i have to say: 1. kinda 2. nop 3. not so much 4. it happens once in a while, but it is usually when i do it alone.
    From DaveK
  • While I completely agree with the Joel Test in terms of the tools to perform your job, a commonly overlooked requirement for a pleasant working environment is your social relationship with your management and your peers.

    One of the largest contributing factors to my being happy at many of the jobs I have had is the word of mouth of the friends who have recommended the job, and even let me use them as a reference.

    From Jason Z
  • You didn't say where you lived.

    I live in a low population area and had a hard time at first. Then I put specific searches on Indeed, SimplyHired and Craigslist and added the result pages to my RSS reader. It took six months from the time I started, but I eventually found a company that values the things I do.

    In a bigger city, I would be checking out job boards from Joel, 37 Signals, and DailyWTF.

    From Lou Franco
  • The things I look for most is the attitude of the people running the place. If they are public or plan to go public, it's a negative, if they are funded by anything but existing sales, then big minus. If they are Google, big plus, ...

    The owner of my current (very small) company is really great--not really out to make money, no thought about going public, an engineer that enjoys solving problems more than running an empire, so well respected in the field that customers call him rather than the company having to sell itself; and no real desire for growth (except that the projects we are on are demanding it). In a small company that's perfect!

    We also virtually never work more than 8 hours a day and out of 20 employees, there doesn't seem to be a single personality conflict (Unless it's me and they just aren't saying anything).

    I'd say don't ask here though, consider what you have liked--for every person it's different and what I think is important may not interest you at all.

    Also, consider it a fact that you will probably change jobs every 3-7 years. Use that fact to try different areas and find what works for you and what doesn't.

    Life is a pretty long race, don't get winded right off the bat, stay in for the long haul :)

    From Bill K
  • I feel your pain. I think the biggest tells for me are the quality of the other developers. To some extent I try to get a sense of this from asking things like

    -what's the turnover rate among developers? (this one hasn't helped me as much as I thought it would)

    -what are the quality of the interview questions? If they're too easy then it's likely that people with insufficient skill have passed them, and it's also likely that they don't know what to look for.

    -what kinds of tools are they using? Some tools are more commonly associated with high-functioning developers. Some places don't even get source code control.

    I've only intermittently found work that's good or great in the sense you're talking about, often because I ignored the warning signs or (more likely) just needed the work.

    From Steve B.
  • Answers to Your first question:

    • Use Your network. Ok, in Your case, that does not seem to help. Try anyway.
    • Use Your modified Joel test in the interview.
    • Ask Your potential new co-workers, how long they have been working for that company. (The longer, the better. Bad working conditions cause shorter durations.)

    Answers to Your second question:

    • It depends on the field You are working in.
      • If You look for an application in security related fields (e.g. car manufacturing), then Your expectations are right.
      • If You look for an application in standard customer software (e.g. computer games, office tools), then Your expectations might(!) be too high.

    It is sad but true, that in some fields, a dirty hack has a higher marketing potential than software produced in a process that passes Your test, because

    • The hack will be available. (It is sold before it's finished.)
    • High software quality is not the most urgent design goal. (compared to release dates and marketing-friendly features)
    • The first version of the hack is extremely cheap to produce compared with proper software development. The next version of the hack may be impossible to produce, but that does not matter to the average manager.
    • Last but not least: A proper development process is often seen as overhead. Most of us know that this is not correct, but management and marketing have their own sources of knowledge.
    From Black
  • A good step is always to try selling yourself and your unique talents. Every programmer with an interest in programming has their own mix of talents which makes them unique. Don't look for job postings--look for organizations that could benefit from what you do. Approach them well-prepared to explain to them what it is exactly you do and how it would benefit them.

    Another perk of this approach is that you might be blazing a new trail for the group you're working with, meaning you might be able to be your own boss in many ways.

    It's not a career path for everybody, and there's a lot of proving yourself involved in it (so be prepared to walk the walk) but I managed to land a development job which directly applies to my master's thesis topic where I still get to do a lot of learning every day this way.

  • Your standards are definitely not too high. Software development is never easy, but it can be as hard as one makes it. I can see no reason not to use tools like version control software, bug databases, and automated testing. One might make an exception for a project scoped so small that you expect to complete it in under a week, but in that case you wouldn't need to be hired for a full-time job to work on it.

    As for how to find a good employer, I think you are already on the right track by being picky and asking lots of questions. Strive to work for the smartest people that you possibly can.

    If you have to, you should take the best job available to you at present and continue to shop around in the off-hours. You might think that having a job already would make you unattractive to other employers, but in the software business I've found that the opposite is often true. When interviewers ask you why you are leaving your current job, tell them that you are looking for more ambitious work.

    edit: Addtionally, I agree with Lou's advice that it's easier to find a good tech employer in a densely populated area. Personally, I was fortunate enough to be hired away from my home town by a developer in a major urban center, and they paid for my relocation. I had three tech jobs in my home town before moving, and none of them were as good as the job I have now.

    From Parappa
  • One question you could ask is "how has your development process changed over the last two years".

    A software team that doesn't have a perfect score on the Joel test (or any process evaluation measure) but is evolving is a good sign.

    At the other hand of the spectrum, I'd be afraid of a team that jumps on every new fad, and answers your question with piles and piles of buzzwords.

    From Kena
  • I quit and started working as an independant consultant. It can be hard work but I'd never go back.

    • I make my own decisions about my work environment and the tools I use.
    • Negotiations happen on equal terms instead of being dictated to me.
    • People treat me with more respect even though I'm doing the same work. They know I'm free to pick and choose my projects.
    • Corporate politics are amusing instead of frustrating when you are not an employee of the company.
    From Andrew
  • I've got one question I always ask in job interviews, usually after a couple of Joel Test-style technical questions:

    "What do you enjoy about working here?"

    The look on their face for the five seconds after you ask will usually tell you everything you need to know. Usually, everyone ends up spouting a canned PR "we're awesome" response after they've had a chance to think about it, but their initial reaction tells volumes. The current all time worst reaction I ever got was the two guys interviewing me going "ummmm..." and staring at each other for, and I'm not joking, 30 seconds. "... the people?" one finally stumbled out.

    On paper, the job looked pretty good - decent pay, decent tech, sane sounding development standards, but after a response like that I knew it wasn't worth my time.

    1. The vast majority of companies do not meet your criteria. Developers are focused on the task at hand, get the code out the door cultures. I believe this is true for IBM to 37 Signals to Apple to Woot! I'm certain that there are folks who jump out of bed to go work at those places and others, but the majority of developers are just regular folks that attend PTA meetings and boy scout camps with their kids.

    2. No, your standards are great! But rather than look for a company that already meets your standards, find one whose IT department would like to move in that direction and champion change from within. I'm worried you would simply look forever for the perfect fit when something close might do.

    From Austin
  • If you have already determined that you need to move on, I'm assuming there is something that is unacceptable with you current arrangement. That might be a good place to start when analyzing other employment opportunities. No sense moving to "same stuff, different place".

    The problem is usually in pin-pointing what defines "good" for you. If you know already, great - if not, a list of things that are important to you in terms of employment always helps me sort out my emotions from the facts. Your list of items above seems heavily weighed on coding/programming specific things - you may want to consider some other factors also, like:

    • do I like the people I work with?
    • do I like the commute/can I work remote?
    • is there a dress code / do I care?
    • free soda? :-)
    • salary (obvious)
    • benefits

    When I've been at the point of considering career options, something that helps me is to take all of the things I need to consider, and listing them out. I give each item a 1-10 value for each employer I'm considering. This gives a "weight" to each item, and helps balance out things like "dress code" and "salary".

    Sometimes even just the process of making the list and taking the time to really think about all of the things that make up the job as a whole gives a different perspective to everything.

    From Sunfish
  • I'd start by looking at the job you will be doing there. I've found that the work you'll be doing trumps the environment.

    For instance one of my life goals was to write my own programming language, the company I now work for has our own programming language as part of our software and I'm in charge of the language compiler/development.

    From chollida
    1. Identifying the "good" places can be in part by looking at where some of the people you look up to develop. For example, I have seen a few developers come from a company called "Thoughtworks" and may try, try, and try again to get in there. If your network isn't much help, try expanding your network would be my suggestion as well as talk to people about why they like this place or that. Sometimes a good place will pop up there.

    2. No, there are some places that develop like you describe. However, they aren't likely to have big signs on the front saying, "We want refactoring specialists," so you may have to find an alternative way in. Another idea to change the process where you are at, if you have enough clout. Sometimes doing things in a better way can grow in a company if they start seeing the dividends of doing so.

    From JB King
  • I found my current company by sheer luck, but I can share some of the important reasons I've spent well over 10 years here:

    • Size: we're still small enough that we all understand the impact of our daily activities on the company's success. We feel the "bottom line" every day.
    • People: I respect and enjoy the people I work with--both employees and customers. We appreciate each other and laugh a lot, even when things aren't going smoothly.
    • Opportunity: With more work than resources, there's always another hat that needs a head beneath it. Also still a forest of trees with low-hanging fruit. You can't avoid success if you look for it.
    • Policies: they're designed for humans, with lives outside the company. We understand what needs to be done and are flexible about how. It's ok to ask for forgiveness instead of permission when we're behind your motivation.
    • Technology: We need to stay current to be competitive. Developers, Sales, and customers think our products are not only useful, but cool.
    • Growth: I learn every day. The lessons are not always technical. :-)
    • Challenge/Adversity: There's still an awful lot that isn't "right," and it's a challenge to inflict your point of view on coworkers at various levels. You don't always win, but you're heard, and you learn that a combination of tact, assertiveness, transparency, and sneakiness often works wonders. And being the "inflictee" is equally helpful for me.

    And, for me, perhaps the most important:

    • CHAOS: Plans and schedules notwithstanding, I never know exactly what I'll be doing tomorrow. Priorities shift, opportunities and emergencies arise constantly. In addition to my primary responsibilities as architect and engineer, I sometimes find myself in management, tech support, counseling, sales engineering, HR, business development, training, QA, manufacturing, customer (and employee) retention, IT, ...

      I'm required to think on my feet, solve unexpected problems, and sometimes, it feels, walk on water. (I have a long way to go, but I often manage to swim.) Becoming bored or stagnating is simply not possible.

    Want a job? :-)

    From Adam Liss

LINQ inner join betwenn Enumerable and DB Table

I'm trying to determine which records to delete from a database when a user submits a form. The page has two CheckBoxList one representing the records before modification and one after.

I can easily get the selected values that need to be deleted like this...

//get the items not selected that were selected before
var oldSelectedItems = from oItem in oldChklSpecialNeeds.Items.Cast<ListItem>()
                       where !(from nItem in newChklSpecialNeeds.Items.Cast<ListItem>()
                               where nItem.Selected
                               select nItem.Value).Contains(oItem.Value)
                           && oItem.Selected
                       select oItem.Value;

now I am trying to do something like this but it isn't allowing it...

var itemsToDelete = from specialNeed in db.SpecialNeeds
                           join oldSelectedItem in oldSelectedItems on specialNeed.SpecialNeedsTypeCd equals oldSelectedItem.Value
                           where specialNeed.CustomerId == customerId

I can easily just use a foreach loop and a .DeleteOnSubmit() for each item but I'm thinking there is a way use functionality of LINQ and pass the whole query result of an inner join to .DeleteAllOnSubmit()

//like so
db.SpecialNeeds.DeleteAllOnSubmit(itemsToDelete);

Any ideas?

  • What is the error you are getting? Is it a type mismatch between SpecialNeedsTypeCd and oldSelectedItem.Value? Have you just omitted the select in the second Linq statement in this post or is that the problem?

    From tvanfosson
  • Local collections can be used in LINQ to SQL with the Contains() method. You can try changing the join clause into a where with Contains():

    var itemsToDelete = from specialNeed in db.SpecialNeeds
                        where oldSelectedItems.Contains(specialNeed.SpecialNeedsTypeCd)
                           && specialNeed.CustomerId == customerId
                        select ...;
    
    ctrlShiftBryan : .Contains is exactly what I needed!
    From Lucas

What does the setting WorkArounds2=8192 do on an ODBC connection?

My company has a 3rd party application that runs on a Progress database. I've been building an application on top of their database using an ODBC connection.

One of the "quirks" of Progress is that it doesn't honor SQL column widths, so it will allow 100 characters in a column defined as a varchar(50). When reading this data via ODBC, I get the following error:

Column test_column in table PUB.test_table has value exceeding its max length or precision.

The support techs at the company that build the application pointed me towards adding some work around flags in the registry for the ODBC connection, however, I can't find any documentation as to what these flags will do or what the possible values are. The registry keys are

KEY_CURRENT_USER->Software->ODBC->ODBC.INI->MyODBCConnectionName->WorkArounds KEY_CURRENT_USER->Software->ODBC->ODBC.INI->MyODBCConnectionName->WorkArounds2

Google has found me other problems that people have solved by adding these flags with specific values (including my personal favourite from The Daily WTF) but I can't find anywhere that tells me what the flags actually do. Do you know?

  • The README file for DataDirect Connect for ODBC (a Unix-based ODBC driver) contains a list of workarounds in the "Driver WorkAround Options" section of the document.

    Stefan Moser : Thanks for the link, but it does not say what WorkArounds2=8192 does.
    From mdb
  • It is a fix for:

    'This error occurs with Microsoft Access 2000 when using the Connect for ODBC drivers to link to a table which has one or more indexes associated with it.'

    DataDirect Support KB

    From Tom Bascom

Operation must use an updatable query. (Error 3073) Microsoft Access

On some Microsoft Access queries, I get the following message: Operation must use an updatable query. (Error 3073). I work around it by using temporary tables, but I'm wondering if there's a better way. All the tables involved have a primary key. Here's the code:

UPDATE CLOG SET CLOG.NEXTDUE = (
    SELECT H1.paidthru 
    FROM CTRHIST as H1
    WHERE H1.ACCT = clog.ACCT AND
    H1.SEQNO = (
        SELECT MAX(SEQNO) 
        FROM CTRHIST 
        WHERE CTRHIST.ACCT = Clog.ACCT AND 
        CTRHIST.AMTPAID > 0 AND
        CTRHIST.DATEPAID < CLOG.UPDATED_ON
    )
)
WHERE CLOG.NEXTDUE IS NULL;
  • Since Jet 4, all queries that have a join to a SQL statement that summarizes data will be non-updatable. You aren't using a JOIN, but the WHERE clause is exactly equivalent to a join, and thus, the Jet query optimizer treats it the same way it treats a join.

    I'm afraid you're out of luck without a temp table, though maybe somebody with greater Jet SQL knowledge than I can come up with a workaround.

    BTW, it might have been updatable in Jet 3.5 (Access 97), as a whole lot of queries were updatable then that became non-updatable when upgraded to Jet 4.

    --
    David W. Fenton
    David Fenton Associates

    Knox : Thanks for the explanation.
    Yarik : So we have a pretty trivial update statement (UPDATE CLOG SET CLOG.NEXDUE = ... WHERE CLOG.NEXTDUE IS NULL), and the only reason why it does not work is that the query used to compute new value of CLOG.NEXDUE is "too complex". Unbelievable!! I am glad we switched from Jet to SQL Server!!! :-))
    David-W-Fenton : I don't believe your assertion that the SQL you quote could ever produce the "query too complex" error in Jet. You are either mistaken, or for some reason I can't fathom, spreading misinformation about Jet.
  • In essence, while your SQL looks perfectly reasonable, Jet has never supported the SQL standard syntax for UPDATE; instead, it uses its own proprietary syntax (different again from SQL Server's proprietary UPDATE syntax) which is VERY limited. Often, the only workarounds "Operation must use an updatable query" are very painful. Seriously consider switching to a more capable SQL product.

    For some more details about your specific problems and some possible workarounds, see

    [http://support.microsoft.com/default.aspx?scid=kb;en-us;116142&Produc][1]

    [1]: http://ACC: Update Query Based on Totals Query Fails

    From onedaywhen
  • The problem defintely relates to the use of (in this case) the max() function. Any aggregation function used during a join (e.g. to retrieve the max or min or avg value from a joined table) will cause the error. And the same applies to using subqueries instead of joins (as in the original code).

    This is incredibly annoying (and unjustified!) as it is a reasonably common thing to want to do. I've also had to use temp tables to get around it (pull the aggregated value into a temp table with an insert statement, then join to this table with your update, then drop the temp table).

    Glenn

    From Glenn M
  • I kept getting the same error until I made the connecting field a unique index in both connecting tables. Only then did the query become updatable.

    Philip Stilianos

    Remou : You may wish to read this article on when queries can be update: http://msdn.microsoft.com/en-us/library/aa198446.aspx
  • Even more maddening -- i have an update query the runs fine using linked tables from a SQL Server database. THE SAME QUERY running against an exact copy of the SAME DATABASE returns "Operation must use an updatable query" -- AARGH!

    No workaround found yet.

    From
  • (A little late to the party...)

    The three ways I've gotten around this problem in the past are:

    1. Reference a text box on an open form
    2. DSum
    3. DLookup
    David-W-Fenton : Temp tables are often faster.
    Knox : Yep, I'm still using Temp tables. I only wish they were really temporary, but I just let them live, and the next time the make table runs, it replaces the previous "temporary" table.
    From mark

C# Abstract class, using anonymous instead of declaring concrete class?

I have an abstract class and I would like to use it quickly by NOT create a concrete class that inherit the abstract class. Well, to define the abstract method anonymously.

Something like that:

           Command c = new Command(myObject){
               public override void Do()
               {
               }                   
            };

Is it possible in C# .net 2.0?

  • You could create a type that wraps an action providing an implementation as such:

    class ActionCommand
    {
        private readonly Action _action;
    
        public ActionCommand(Action action)
        {
            _action = action;
        }
    
        public override void Do()
        {
            _action();
        }                   
    };
    

    This then can be used as so:

    Command c = new Command((Action)delegate()
               {
                  // insert code here
               });
    

Is it a good idea to use Active Directory user login to your application.

I am developing a web based intranet for my company. I just want to know is it a good thing for users to login the application using the active directory login details or shall i create a login together with the application db. If there is anything better that this please suggest. This is my first application development so need help from experienced people.

  • If you create a separate login system, then your users have to remember 2 different logins. Why bother, when their "real" login is right at hand?

    From Danimal
  • Less code for you to write and better integration into the wider system. And, who doesn't want FEWER passwords to remember.

  • Generally it's a good idea to try and minimize the number of accounts people need to have.
    So I'd definately try and use their active directory login.

    Also if desireable, you can automatically log people into your application using various single sign on methods. (Either integrated into IIS, or other.).
    This makes for a very usable application, as people always forget login details, and hate to login again to other systems.

    jazzrai : can i get some reference reading material on this "automatically log people into your application using various single sign on methods. (Either integrated into IIS, or other.)."
    Bravax : Nico's reply has a link which explains various options.
    From Bravax
  • Only use Active directory for your intranet, if you infrastructure supports it.

    You question is phrased as if you think the user to type there password in again to login to the intranet site - they should not do this! have windows pass on the credentials automatically. This is pretty much built in to dotnet/iis/etc.

    Also AD will add group management a privledges so you can restrict areas of you intranet to members of certain groups.

    And you support team already have the tools to manage all this.

    PS you can enable FireFox to auto log on via NTLM and it is one of the most requested features for Chrome too so don't let browser issues put you off

    jms : In IIS check out Integrated Authentication.
    From Adrian
  • There are several pros using Active Directory authentication in the intranet.

    Thoses are the main ones:

    • You want to to keep authentication stores number as low as possible
    • Using Active Directory, users who have their desktop in the domain (as they should) will be able to use Integrated Windows Authentication. They will be able to log in without having to type their password.
    • An Active Directory authentication mechanism probably exists for your language

    More information:

    From Nico
  • on topic.
    http://stackoverflow.com/questions/22135/how-do-i-use-ntlm-authentication-with-active-directory#22191

    From jms
  • Definitely go for the Active Directory option, or use Active Directory as an LDAP server if whatever language you're using doesn't directly support AD. Active Directory actually makes a pretty good LDAP server.

    If there is anything better that this please suggest.

    OpenID?...

    jcm : Why not both? http://www.openid-ldap.org/ allows you to create your own OpenID provider using your existing AD accounts. It's pure nerdgasm.

How can I dynamically change the Active Record database for all models in Ruby on Rails?

In our program, each customer gets their own database. We e-mail them a link that connects them to their database. The link contains a GUID that lets the program know which database to connect to.

How do I dynamically and programatically connect ActiveRecord to the right db?

  • you can change the connection to ActiveRecord at any time by calling ActiveRecord::Base.establish_connection(...)

    IE:

     ActiveRecord::Base.establish_connection({:adapter => "mysql", :database => new_name, :host => "olddev",
        :username => "root", :password => "password" })
    
    From Tilendor
  • You can also do this easily without hardcoding anything and run migrations automatically:

    customer = CustomerModel.find(id)
    spec = CustomerModel.configurations[RAILS_ENV]
    new_spec = spec.clone
    new_spec["database"] = customer.database_name
    ActiveRecord::Base.establish_connection(new_spec)
    ActiveRecord::Migrator.migrate("db/migrate_data/", nil)
    

    I find it useful to re-establish the old connection on a particular model afterwards:

    CustomerModel.establish_connection(RAILS_ENV)
    
    From Jim Puls

Losing Button.Click events after first partial postback in UpdatePanel

I have a Page that has a single instance of a UserControl that itself has a single UpdatePanel. Inside the UpdatePanel are several Button controls. The Click event for these controls are wired up in the code-behind, in the Init event of the UserControl.

I get the Click event for the first button I push, every time, no problem. After that, I only get Click events for one button (SearchButton) - the rest are ignored. I have included the code for the control below - for sake of brevity, I have excluded the click event handler methods, but they are all of the standard "void Button_Click(object sender, EventArgs e)" variety. Any ideas?

<asp:UpdatePanel ID="PickerUpdatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Panel ID="Container" runat="server">
            <div>
                <asp:TextBox ID="PickerResults" runat="server" style="margin-right: 3px;" SkinID="Plain" />
                <asp:Image
                    ID="LaunchPopup" runat="server" ImageUrl="~/images/icons/user_manage.png" 
                    ImageAlign="Top" BorderColor="#294254" BorderStyle="Dotted" BorderWidth="1px" 
                    Height="20px" Width="20px" style="cursor: pointer;" />
            </div>
            <asp:Panel ID="PickerPanel" runat="server" DefaultButton="OKButton" CssClass="popupDialog" style="height: 227px; width: 400px; padding: 5px; display: none;">
                <asp:Panel runat="server" id="ContactPickerSearchParams" style="margin-bottom: 3px;" DefaultButton="SearchButton">
                    Search: <asp:TextBox ID="SearchTerms" runat="server" style="margin-right: 3px;" Width="266px" SkinID="Plain" />
                    <asp:Button ID="SearchButton" runat="server" Text="Go" Width="60px" SkinID="Plain" />
                </asp:Panel>
                <asp:ListBox ID="SearchResults" runat="server" Height="150px" Width="100%" SelectionMode="Multiple" style="margin-bottom: 3px;" />
                <asp:Button ID="AddButton" runat="server" Text="Add >>" style="margin-right: 3px;" Width="60px" SkinID="Plain" />
                <asp:TextBox ID="ChosenPeople" runat="server" Width="325px" SkinID="Plain" />
                <div style="float: left;">
                    <asp:Button ID="AddNewContact" runat="server" SkinID="Plain" Width="150px" Text="New Contact" />
                </div>
                <div style="text-align: right;">
                    <asp:Button ID="OKButton" runat="server" Text="Ok" SkinID="Plain" Width="100px" />
                </div>
                <input id="SelectedContacts" runat="server" visible="false" />
            </asp:Panel>
            <ajax:PopupControlExtender ID="PickerPopEx" runat="server" PopupControlID="PickerPanel" TargetControlID="LaunchPopup" Position="Bottom" />
        </asp:Panel>
   </ContentTemplate>
   <Triggers>
        <asp:AsyncPostBackTrigger ControlID="AddButton" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="SearchButton" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="AddNewContact" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

public partial class ContactPicker : System.Web.UI.UserControl
{
    protected void Page_Init(object sender, EventArgs e)
    {
        SearchButton.Click += new EventHandler(SearchButton_Click);
        AddButton.Click += new EventHandler(AddButton_Click);
        OKButton.Click += new EventHandler(OKButton_Click);
    }

    // Other code left out
}
  • It seems that adding UseSubmitBehavior="false" to the button definitions has solved my problem. Still don't know why that first button click worked at all.

  • The most likely reason for this would be the client IDs that .Net generates for its controls changing. These are dynamically assigned and could change between postbacks / partial postbacks.

    If controls are being added to the panel dynamically, the ID of your button could be different between postbacks causing .Net to be unable to tie the click event to the correct event handler in your code.

    From Blatfrig
  • and how would one work around this problem, Blatfig?

What is the best way for a Java program to monitor system health?

I would like to be able to monitor my major system health indicators from inside our Java-based system. Major points of interest include CPU temperature, motherboard temperature, fan speed, etc.

Is there a package available that:

  1. Makes this sort of data available to Java?
  2. Works on Windows or Linux or both?
  3. Is open / free / cheap?
  • A few months ago I looked for such a library and I found nothing interesting. It is not impossible to create one, so I would recommend doing so. You'll probably need to access native libraries, to do that use JNA (it's easier than JNI). Start by adding support for a few things on one platform, then start adding support for other features and platforms.

    The share it with us! People will starts using it, maybe even help with development and soon you'll have a fully featured system monitoring library for Java.

    Bob Cross : Thanks, I had never heard of JNA.
  • JMX + JNI = YourSolution

    Bob Cross : This isn't really an answer. Do you have something specific in mind?
    From l_39217_l
  • The closest thing you'll find is the Hyperic Sigar library:

    http://www.hyperic.com/products/sigar.html

    It doesn't get down to temperatures AFAIK but does show you a number of native stats like CPU, memory, disk I/O, network I/O, etc. It's ported to most of the architectures people are deploying Java on today. License is GPL although I think you can buy commercial licenses as well.

    We use Sigar with Terracotta for cluster monitoring and have been very happy with it.

    Bob Cross : CPU temperature is something that we specifically need so this is a major limitation.
  • I believe most of this sort of thing is usually done over SNMP (for professional system) is the usual way to make this sort of information available in a standards-based manner. JMX is also available over SNMP. The question then becomes, which are the better SNMP libraries for Java (and does your system support it)?

  • There are MIBs supported by both Windows and Linux that expose the parameters you are looking for via SNMP. Also, most major vendors have special MIBs published for their server hardware.

    I have implemented SNMP MIBs and monitoring for Java applications using the commercial iReasoning SNMP API and they worked great. There is also the open source SNMP4J, which I don't personally have experience with, but looks pretty good.

    So, for your needs, you would turn on the publishing of SNMP information for the hosts you want to monitor. No coding necessary. This is just a configuration issue.

    For CPU temperature, for example, you must enable the MIB LM-SENSORS-MIB. Under Linux you can use the snmpwalk client to take a look at OID .1.3.6.1.4.1.2021.13.16.2.1.3 to see CPU temperature. Once you have that up and you know it's publishing data correctly, you can begin to implement your real monitoring solution.

    You can use a Java SNMP library to poll and subscribe to SNMP traps for the hosts you want to monitor. You could also use any commercial or open-source monitoring tool (Google for SNMP console).

    From shadit
  • This is a good link providing information on Java SE monitoring and management... http://java.sun.com/javase/6/docs/technotes/guides/management/toc.html

    Thanks, JC

Visual Designer errors, when there are no errors

I get errors when viewing forms and there are not any. I can close VS and reopen and it is fine. What cases this? Can it be fixed without closing?

  • what's on your form? Is it only .Net controls or some 3rd party/custom user control?

    Try it in debug mode step by step if you just have no hope left...

    From Miles
  • It has custom user controls. Within the solution.

    From nportelli
  • Verify none of your custom user controls has any code errors.

    Also try starting up Visual Studios using devenv /resetskippkgs from the command prompt. It will reset packages if there is an error in loading.

C# Save Dialog box

I've got a save dialog box which pops up when i press a button. However i dont want to save a file at that point, i want to take the name and place it in the text box next to the button, for the name to be used later.

Can anybody tell me how to obtain the file path from the save dialog box to use it later?

  • Here is a sample code I just wrote very fast... instead of Console.Write you can simply store the path in a variable and use it later.

    SaveFileDialog saveFileDialog1 = new SaveFileDialog(); 
    saveFileDialog1.InitialDirectory = Environment.SpecialFolder.MyDocuments; 
    saveFileDialog1.Filter = "Your extension here (*.EXT)|*.ext|All Files (*.*)|*.*" ; 
    saveFileDialog1.FilterIndex = 1; 
    
    if(saveFileDialog1.ShowDialog() == DialogResult.OK) 
    { 
     Console.WriteLine(saveFileDialog1.FileName);//Do what you want here
    }
    
    From Daok
  • Addressing the textbox...

    if (saveFileDialog.ShowDialog() == DialogResult.OK)
    {
        this.textBox1.Text = saveFileDialog.FileName;
    }
    
    From JTA

How to preview git-pull without doing fetch?

Is it even possible?

Basically, there's a remote repository from which I pull using just:

git pull

Now, I'd like to preview what this pull would change (a diff) without touching anything on my side. The reason is that thing I'm pulling might not be "good" and I want someone else to fix it before making my repository "dirty".

  • I think git fetch is what your looking for.

    It will pull the changes and objects without committing them to your local repo's index.

    They can be merged later with git merge.

    Man Page

    Edit: Further Explination

    Straight from the Git- SVN Crash Course link

    Now, how do you get any new changes from a remote repository? You fetch them:

    git fetch http://host.xz/path/to/repo.git/
    

    At this point they are in your repository and you can examine them using:

    git log origin
    

    You can also diff the changes. You can also use git log HEAD..origin to see just the changes you don't have in your branch. Then if would like to merge them - just do:

    git merge origin
    

    Note that if you don't specify a branch to fetch, it will conveniently default to the tracking remote.

    Reading the man page is honestly going to give you the best understanding of options and how to use it.

    I'm just trying to do this by examples and memory, I don't currently have a box to test out on. You should look at:

    git log -p //log with diff
    

    A fetch can be undone with git reset --hard (link) , however all uncommitted changes in your tree will be lost as well as the changes you've fetched.

    Milan Babuškov : If you explain two things, that might be good: 1. how do I undo git-fetch? 2. How do I see the diff?
    Christian Vest Hansen : 1) undoing git-fetch? 2) git diff HEAD..origin
    Brian Gianforcaro : The diff is done as Christian said, a fetch can be undone with git reset --hard , however all uncommitted changes in your tree will be lost as well as the changes you've fetched.
    Aristotle Pagaltzis : Are you looking for `git reset --soft` or `--mixed`? Check the manpage.
  • After doing a git fetch, do a git log HEAD..origin to show the log entries between your last common commit and the origin branch. To show the diffs, use either git log -p HEAD..origin to show each patch, or git diff HEAD...origin (three dots not two) to show a single diff.

    There normally isn't any need to undo a fetch, because doing a fetch only updates the remote branch and none of your branches. If you're not prepared to do a pull and merge in all the remote commits, you can use git cherry-pick to accept only the specific remote commits you want. Later, when you're ready to get everything, a git pull will merge in the rest of the commits.

    Update: I'm not entirely sure why you want to avoid the use of git fetch. All git fetch does is update your local copy of a remote branch. This local copy doesn't have anything to do with any of your branches, and it doesn't have anything to do with uncommitted local changes. I have heard of people who run git fetch in a cron job because it's so safe.

    Milan Babuškov : I guess I missed that part of 'nothing to do with MY branches' while reading the docs. Thanks.