如何检查我的SQL Server Express数据库是否超过10 GB的大小限制? [英] How to check if my SQL Server Express database exceeds the 10 GB size limit?

查看:1183
本文介绍了如何检查我的SQL Server Express数据库是否超过10 GB的大小限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网站,该网站的数据库使用SQL Server 2008 R2 Express.在测试中,该数据库中存储了很多数据和图像.

I am developing a web site, it uses SQL Server 2008 R2 Express for its database. And in testing, there is a lot of data and images stored into this database.

根据Wiki,SQL Server Express版本的大小限制为 10 GB .当我插入数据并达到限制时,将引发什么异常?或者,如何通过代码检测接近极限问题?

According to wiki, the SQL Server Express edition has a 10 GB size limit. When I insert data and reach the limit, what exception will be thrown? Or, how do I detect the approaching limit problem by codes ?

我使用带有代码优先方法的EF 5插入大数据集.

I use EF 5 with code-first approach to insert large data set.

推荐答案

在测试中,我看到了:

sp_spaceused

无法正常工作,删除大量记录后显示12GB.而且关于查询sys.databases的其他答案对我来说还不够清楚.

won't work as expected, it showed 12GB after deleting lots of records. And the other answers regarding query sys.databases were not clear enough to me.

四处搜寻,我在"...空间包括事务日志,并且还包括这些文件中所有未使用的空间.....当SQL Server Express无法为数据文件保留更多空间时,它将开始抱怨."

"... space includes the transaction log and it also includes all unused space within these files. .... SQL Server Express will start complaining when it cannot reserve any more space for the datafile."

请检查

CAST(FILEPROPERTY([name],'SpaceUsed') AS int)/128.0 AS [UsedSpaceInMB]

似乎是最好的选择.

我对数据库的请求看起来像

In combination with EF in c# my request to the DB looks like

string sqlSelect = "SELECT CAST(FILEPROPERTY([name],'SpaceUsed') AS int)/128.0 AS [UsedSpaceInMB] FROM sys.database_files";
var dbResult = dbInstance.Database.SqlQuery<Decimal>(sqlSelect).FirstOrDefault();
double spaceUsedInGb = Convert.ToDouble(dbResult)/1024;

这篇关于如何检查我的SQL Server Express数据库是否超过10 GB的大小限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆