tags:

views:

67

answers:

2

Hi, I need to know a way to show a message or something like that when I compile my program and the user or password are wrong, because when I do this nothing happens.

I'm making a system that save logs.

log4net just using C#. if you can help me I'd appreciate.

thanks!

+2  A: 

I don't think there is a way to do it at compile time, as far as I know.

Assuming you meant run time instead of compile time makes more sense. When you try to open the connection, use a try-catch block, and inside the catch block, log the error, display an alert, do whatever you need to do.

Is this what you need or can you give a more specific problem?

Brandi
+1  A: 

If it is absolutely a requirement that the project not build if the connection string is invalid you can do something that is approximately like the following.

  1. Store the username/password in some external/known location. i.e. config file.
  2. Write a "DBConnect" app. All it does is load the connection, and have it exit with an error code if it cannot connect.
  3. Include this "DBConnect.exe" in the pre-build of the particular project.

TaDa! The project will not build unless the connection string is valid.

Keep in mind, this only validates that the connection string is valid from the build machine. It does not validate that it can be accessed from anywhere else.