0

Using IDataReader in c# to pull a list of host names from a database that correspond to a specific business unit, but can't figure out what is wrong. I am guessing that there are too many arguments in the SQL statement, or perhaps the ExecuteReader method here should not be used. I cannot create a SP in the target DB so I am left with running the query in some other manner. Any help will be greatly appreciated.

    public static IDataReader GetCETHostsList()
    {
        string mySQL = @"SELECT distinct(dbo.Infrastructure.Hostname) dbo.Application_Infrastructure 
                        INNER JOIN dbo.Applications ON dbo.Application_Infrastructure.ID = dbo.Applications.ID
                        INNER JOIN dbo.Infrastructure ON dbo.Application_Infrastructure.InfrastructureID = dbo.Infrastructure.InfrastructureId 
                        WHERE Unit is not null
                        AND dbo.Applications.Unit like '%Terminal%' 
                        AND (dbo.Infrastructure.Hostname like '%ST%' or dbo.Infrastructure.Hostname like '%TR%' )";
        return DatabaseFactory.CreateDatabase("myDB").ExecuteReader(mySQL);
    }

1 Answers1

1

You're missing the FROM keyword.

Generally, if you use SQL embedded in C# programs, it's really a lot easier if you run the SQL in Query Analyzer / SQL Management Studio or something first. MS SQL Express is free; or VS Pro can run sql queries too.

Chris F Carroll
  • 11,146
  • 3
  • 53
  • 61