0

I'm working on a C# application, based on Telerik's OpenAccess technology.

The following piece of source code does not give any results (although the corresponding table contains a lot of data):

List<Setting> lijst = new List<Setting>();
try { 
    lijst = database.GetData<Setting>().ToList();
}
catch (Exception e)
{
    log.Error($"Exception: [{e}], Message=[{e.Message}]");
}
log.Debug($"Count=[{lijst.Count()}]");

However, the following piece of source code (from another, similar program) does give results:

internal static IEnumerable<Lift> GetAll(IDatabaseConnection database)
{  
    return database.GetData<Lift>();
}

The only difference is can find, are the connectionstrings (according to the watch-windows):

  • Non-working application : "Data Source=localhost\\SQLEXPRESS;..."
  • Working application : "Data Source=localhost\SQLEXPRESS;..."

As you can see, one contains a single backslash, the other a double one.

However, both strings are created the same way:

  • Non-working application : Settings.DatabaseAddress = @"localhost\SQLEXPRESS";
  • Working application : Settings.DatabaseAddress = @"localhost\SQLEXPRESS";

Am I on the right track and are those single/double characters indeed an indication, explaining the wrong database behaviour, or am I on the wrong track here?

For your information: I'm working with Visual Studio 2022, version 17.5.5.

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • 1
    _The following piece of source code does not give any results_ is not the same as not connecting in the first place. – Salman A May 30 '23 at 12:49
  • 1
    If the connection was truly the problem, you'd be getting an error, not an empty result set. *Are* you getting an error, or is your local database/table just empty? Note that the pieces of code you quote are not attempting to retrieve the same table. – Jeroen Mostert May 30 '23 at 12:50
  • Who knows, you gave way too little info in some code snippets, why not just debug the code and follow the money – siggemannen May 30 '23 at 12:55
  • @siggemannen: that's the problem: the `DatabaseAddress` entries are used somewhere inside the Telerik "OpenAccess" source code, so I don't see what's happening there. I can tell you that my source code does not generate an exception (hence the `try-catch` construction). – Dominique May 30 '23 at 12:57
  • well, if you have a watch, you can set a breakpoint when the value changes, so you can track when it gets this extra slash – siggemannen May 30 '23 at 13:10
  • If both are set exactly same way, it is just the tool you are using to view the string. In VS a backslash will be shown as two backslashes to distinguish from a control character. – jdweng May 30 '23 at 13:25
  • @The fact that the same (or a very similar) string is shown in two very different ways looks like a bug to me, don't you think? – Dominique May 30 '23 at 13:42
  • Did you manage to trace it? – siggemannen Jun 02 '23 at 13:36
  • Sounds to me like the SQL Express instance installed and running on your computer has the database and tables created but they're not populated with any data. More likely anything else (ranging from incorrect connection strings, non-existent databases, incorrect login-user mappings, etc.) would result in some kind of exception message getting thrown. – AlwaysLearning Jun 03 '23 at 08:01

0 Answers0