I have the following, using Kentico API 7 via a console application:
String connectionString = CMS.DataEngine.ConnectionHelper.GetConnectionString(\"MyConnString
It certainly is possible to use Kentico API outside of Kentico itself. Recently, I published an article on this topic. However, the article demonstrates the possibility on a newer version of Kentico. But back to your problem...
The CMS.CMSHelper.CMSContext.Init();
method expects a connection string named "CMSConnectionString" to exist in your app.config or web.config.
The documentation also says
You can call this method at any point in your application's life cycle, but it must occur before you use any other Kentico CMS API.
so you should not be touching CMS.DataEngine
or any other CMS.*
namespace before you call CMSContext.Init()
.
Once you call that method you can start using the parameter-less overload ConnectionHelper.GetConnection()
but I would advise you to take advantage of the Info-Provider pattern that Kentico offers instead of using the direct DB access through CMS.DataEngine
.
For instance, this is how you delete users:
// Get the user
UserInfo deleteUser = UserInfoProvider.GetUserInfo("MyNewUser");
// Delete the user
UserInfoProvider.DeleteUser(deleteUser);