I have the following, using Kentico API 7 via a console application:
String connectionString = CMS.DataEngine.ConnectionHelper.GetConnectionString(\"MyConnString
Unless there's a specific need to create a console application to perform your task, then I would recommend avoiding a console app and instead creating a custom scheduled task.
You can write the code that your task needs to perform within the App_Code folder of your project - or within the CMSAppCode project if you're using a web application project type. This way you don't have to worry about having access to the database or referencing all the DLLs you'll need to utilize the Kentico API.