如何使用SMO显示ndf文件?

发布于 2024-08-06 21:53:09 字数 536 浏览 3 评论 0原文

我正在使用 SMO 填充数据库文件日志文件列表。我正在使用文件组,但它仅显示 mdf 和 ldf 文件。我有 ndf 文件,它也不显示 ndf 文件吗?我有什么建议吗???

           string dbname = string.Empty, DatabaseInfo = string.Empty;
           Server srv = new Server(instanceName);
           foreach (Database db in srv.Databases)
           {
                 if (DB.Equals(db.Name))
                 {
                   DatabaseInfo += db.FileGroups[0].Files[0].FileName;
                  string logfile=db.LogFiles[0].FileName ;           

                 }
           }

I am using SMO to populate the list of database files log files. i am using filegroups but it displays only mdf and ldf files. I have ndf files also it is not dispalying ndf files?? what i have to do any suggestions plz???

           string dbname = string.Empty, DatabaseInfo = string.Empty;
           Server srv = new Server(instanceName);
           foreach (Database db in srv.Databases)
           {
                 if (DB.Equals(db.Name))
                 {
                   DatabaseInfo += db.FileGroups[0].Files[0].FileName;
                  string logfile=db.LogFiles[0].FileName ;           

                 }
           }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傻比既视感 2024-08-13 21:53:09

抱歉,如果这说明了一些显而易见的事情,但您正在专门访问第一个文件组和该组的第一个文件。如果您不枚举文件组和文件集合,为什么您会期望看到辅助文件?

编辑:添加了代码摘录。

foreach (Database db in srv.Databases)  
{
    if (DB.Equals(db.Name))                 
    { 
            foreach (FileGroup fg in db.FileGroups)
            {
                foreach(DataFile df in fg.Files)
                {
                    // do whatever you planned to do with df.FileName.
                }
            }
            foreach (LogFile log in db.LogFiles)
            {
                // do whatever you planned to do with the log.FileName
            }
    }
}

Sorry if this is stating something a bit obvious, but you are specifically accessing the first filegroup and first file of that group. If you do not enumerate the filegroups and files collection, why would you expect to see the secondary files?

Edit : Added a code extract.

foreach (Database db in srv.Databases)  
{
    if (DB.Equals(db.Name))                 
    { 
            foreach (FileGroup fg in db.FileGroups)
            {
                foreach(DataFile df in fg.Files)
                {
                    // do whatever you planned to do with df.FileName.
                }
            }
            foreach (LogFile log in db.LogFiles)
            {
                // do whatever you planned to do with the log.FileName
            }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文