Testing an Entity Framework database connection

前端 未结 6 1666
我在风中等你
我在风中等你 2020-12-08 04:34

I have an app that connects to a MYSQL database through the entity framework. It works 100% perfectly, but I would like to add a small piece of code that will test the conne

6条回答
  •  臣服心动
    2020-12-08 04:53

    In EntityFramework Core you can simply call: Database.CanConnect();.

    (using EF Core 2.2.1)

    Summary: Determines whether or not the database is available and can be connected to.

    Note that being able to connect to the database does not mean that it is up-to-date with regard to schema creation, etc.

提交回复
热议问题