Database information

2 posts, 0 answers
  1. Manuel
    Manuel avatar
    43 posts
    Member since:
    Jul 2010

    Posted 12 Mar 2014 Link to this post

    Hi!

    Is it possible to receive some information about the used database?
    E.g. Database exists, Database version, instance name, SQL Version, SQL Server Edition....

    Thank you,
    Manuel
  2. Boyan
    Admin
    Boyan avatar
    100 posts

    Posted 14 Mar 2014 Link to this post

    Hi Manuel,

    You could expose information about the backend you are working through the context extending it the following way:
    public partial class EntitiesModel
    {
        public Telerik.OpenAccess.BackendConfiguration.BackendInformation GetDatabaseInformation()
        {
            var scope = this.GetScope();
            var backendInfo = scope.Database.BackendConfiguration.BackendInfo;
            return backendInfo;
        }
    }

    Additionally, through the GetSchemaHandler() method of a context you could get a schema handling instance which will tell you if a database exists and will help you to create/update the database schema by executing and generating DDL scripts. Please refer to this documentation article for more information on how to handle schema migration.

    As an alternative, through the ADO api Telerik Data Access allows you to execute any custom script you wish. You could use that to execute queries which return information about the database instance provided that you have sufficient rights. For example, you could get the instance name (or other information you are interested in) in the following way:

    var context = new EntitiesModel();
    var result = context.ExecuteScalar<string>("SELECT @@servername");

    Please note that this may require backend specific code which probably will not work if you change the backend.

    Should you have any further questions, please let us know. 

    Regards,
    Boyan
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
Back to Top