Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server StackOverflow导入错误:LOB超过2147483647字节?_Sql Server_Sql Server 2005_Stack Overflow - Fatal编程技术网

Sql server StackOverflow导入错误:LOB超过2147483647字节?

Sql server StackOverflow导入错误:LOB超过2147483647字节?,sql-server,sql-server-2005,stack-overflow,Sql Server,Sql Server 2005,Stack Overflow,下载并运行Brent's后,我收到以下消息: Msg 7119, Level 16, State 1, Procedure sp_xml_preparedocument, Line 1 Attempting to grow LOB beyond maximum allowed size of 2,147,483,647 bytes. Msg 8179, Level 16, State 5, Procedure usp_ETL_Load_Posts, Line 59 Could not find

下载并运行Brent's后,我收到以下消息:

Msg 7119, Level 16, State 1, Procedure sp_xml_preparedocument, Line 1
Attempting to grow LOB beyond maximum allowed size of 2,147,483,647 bytes.
Msg 8179, Level 16, State 5, Procedure usp_ETL_Load_Posts, Line 59
Could not find prepared statement with handle 0.
The statement has been terminated.
Msg 7102, Level 20, State 99, Procedure usp_ETL_Load_Posts, Line 121
Internal Error: Text manager cannot continue with current statement. 
    Run DBCC CHECKTABLE.
布伦特的查询是基于7月份的数据,我怀疑这是9月份数据库大得多的结果

除了获取较旧的数据外,有人知道如何修复此问题或以其他方式导入数据吗


更新:我正在运行”版本:Microsoft SQL Server 2005-9.00.1399.06(英特尔X86)2005年10月14日00:33:37版权所有(c)1988-2005 Windows NT 5.1上的Microsoft Corporation Developer Edition(Build 2600:Service Pack 3)

SQL Server没有任何数据类型能够在一行的列中存储超过2 GB的数据


如果您有足够的磁盘空间,数据库(Express Edition除外)可以存储超过2GB的数据,但对一行中一列数据量的限制适用。

我通过在.Net中编写一个小型控制台应用程序(下面的代码)解决了这个问题。它一次导入记录1(甚至没有花时间处理sqlbulkcopy对象),并在我午休时运行。我忘了给控制台写时间戳,所以我不知道花了多长时间。我最好的估计是20分钟多一点。请注意,下一个问题是tempdb:如果保留默认设置,tempdb将在导入过程中变得非常大。完成sql server服务后,您将需要重新启动该服务

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Xml;
namespace ImportPostsTable
{
    class Program
    {
        //TODO: pull connection string, data path from app.config or command line
        static string cnString = "Data Source=localhost;Database=SO;Trusted_Connection=True;";
        static string dataPath = @"C:\temp"; 
        static string insertString = "INSERT INTO Posts VALUES (@Id, @PostTypeID, @AcceptedAnswerId, @CreationDate, @Score, @ViewCount, @Body, @OwnerUserId, @OwnerDisplayName, @LastEditorUserId, @LastEditDate, @LastActivityDate, @Title, @Tags, @AnswerCount, @CommentCount, @FavoriteCount, @ClosedDate, @ParentId)";
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());

            try
            {
                 ImportPosts(dataPath, cnString);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
                Trace.WriteLine(e.StackTrace);
            }
            Console.ReadKey(true);
        }

        public static void ImportPosts(string XmlPath, string ConnectionString)
        {
            using (StreamReader sr = new StreamReader(Path.Combine(XmlPath, "posts.xml")))
            using (XmlTextReader rdr = new XmlTextReader(sr))
            using (SqlConnection cn = new SqlConnection(ConnectionString))
            using (SqlCommand cmd = new SqlCommand(insertString, cn))
            {
                cmd.Parameters.Add("@Id", SqlDbType.Int);
                cmd.Parameters.Add("@PostTypeId", SqlDbType.Int);
                cmd.Parameters.Add("@AcceptedAnswerId", SqlDbType.Int);
                cmd.Parameters.Add("@CreationDate", SqlDbType.DateTime);
                cmd.Parameters.Add("@Score", SqlDbType.Int);
                cmd.Parameters.Add("@ViewCount", SqlDbType.Int);
                cmd.Parameters.Add("@Body", SqlDbType.NVarChar);
                cmd.Parameters.Add("@OwnerUserId", SqlDbType.Int);
                cmd.Parameters.Add("@OwnerDisplayName", SqlDbType.NVarChar, 40);
                cmd.Parameters.Add("@LastEditorUserId", SqlDbType.Int);
                cmd.Parameters.Add("@LastEditDate", SqlDbType.DateTime);
                cmd.Parameters.Add("@LastActivityDate", SqlDbType.DateTime);
                cmd.Parameters.Add("@Title", SqlDbType.NVarChar, 250);
                cmd.Parameters.Add("@Tags", SqlDbType.NVarChar, 150);
                cmd.Parameters.Add("@AnswerCount", SqlDbType.Int);
                cmd.Parameters.Add("@CommentCount", SqlDbType.Int);
                cmd.Parameters.Add("@FavoriteCount", SqlDbType.Int);
                cmd.Parameters.Add("@ClosedDate", SqlDbType.DateTime);
                cmd.Parameters.Add("@ParentId", SqlDbType.Int);

                Trace.Write(DateTime.Now.ToString() + Environment.NewLine + "Reading");
                int count = 0;
                cn.Open();
                while (rdr.Read())
                {
                    if (rdr.AttributeCount <= 5) continue; //everything but the xml declaration and the root element will have at least 5 attributes

                    cmd.Parameters[0].Value = rdr["Id"];
                    cmd.Parameters[1].Value = rdr["PostTypeId"];
                    cmd.Parameters[2].Value = rdr["AcceptedAnswerId"];
                    cmd.Parameters[3].Value = ParseDate(rdr["CreationDate"]);
                    cmd.Parameters[4].Value = rdr["Score"];
                    cmd.Parameters[5].Value = rdr["ViewCount"];
                    cmd.Parameters[6].Value = rdr["Body"];
                    cmd.Parameters[7].Value = rdr["OwnerUserId"];
                    cmd.Parameters[8].Value = rdr["OwnerDisplayName"];
                    cmd.Parameters[9].Value = rdr["LastEditorUserId"];
                    cmd.Parameters[10].Value = ParseDate(rdr["LastEditDate"]);
                    cmd.Parameters[11].Value = ParseDate(rdr["LastActivityDate"]);
                    cmd.Parameters[12].Value = rdr["Title"];
                    cmd.Parameters[13].Value = rdr["Tags"];
                    cmd.Parameters[14].Value = rdr["AnswerCount"];
                    cmd.Parameters[15].Value = rdr["CommentCount"];
                    cmd.Parameters[16].Value = rdr["FavoriteCount"];
                    cmd.Parameters[17].Value = ParseDate(rdr["ClosedDate"]);
                    cmd.Parameters[18].Value = rdr["ParentId"];

                    for (int i = 0; i < cmd.Parameters.Count; i++)
                        if (cmd.Parameters[i].Value == null)
                            cmd.Parameters[i].Value = DBNull.Value;

                    cmd.ExecuteNonQuery();

                    if (count++ % 5000 == 0) Trace.Write(".");
                }
                Trace.WriteLine(string.Format("\n\n{0:d}\nFinished {1} records.", DateTime.Now, count));
            }
        }

        public static object ParseDate(string dateValue)
        {
            if (string.IsNullOrEmpty(dateValue)) return DBNull.Value;
            return DateTime.ParseExact(dateValue, "yyyy-MM-ddTHH:mm:ss.fff", null);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统文本;
使用系统诊断;
使用系统数据;
使用System.Data.SqlClient;
使用System.IO;
使用System.Xml;
命名空间ImportPostsTable
{
班级计划
{
//TODO:从app.config或命令行提取连接字符串、数据路径
静态字符串cnString=“Data Source=localhost;Database=SO;Trusted_Connection=True;”;
静态字符串数据路径=@“C:\temp”;
static string insertString=“插入Posts值(@Id、@PostTypeID、@AcceptedAnswerId、@CreationDate、@Score、@ViewCount、@Body、@OwnerUserId、@OwnerDisplayName、@LastEditorUserId、@lastedDate、@LastActivityDate、@Title、@Tags、@AnswerCount、@CommentCount、@FavoriteCount、@ClosedDate、@ParentId)”;
静态void Main(字符串[]参数)
{
添加(新的ConsoleTraceListener());
尝试
{
ImportPosts(数据路径,cnString);
}
捕获(例外e)
{
Trace.WriteLine(e.Message);
Trace.WriteLine(如StackTrace);
}
Console.ReadKey(true);
}
公共静态void ImportPosts(字符串XmlPath、字符串ConnectionString)
{
使用(StreamReader sr=newstreamreader(Path.Combine(XmlPath,“posts.xml”))
使用(XmlTextReader rdr=新的XmlTextReader(sr))
使用(SqlConnection cn=newsqlconnection(ConnectionString))
使用(SqlCommand cmd=newsqlcommand(insertString,cn))
{
cmd.Parameters.Add(“@Id”,SqlDbType.Int);
cmd.Parameters.Add(“@PostTypeId”,SqlDbType.Int);
cmd.Parameters.Add(“@AcceptedAnswerId”,SqlDbType.Int);
cmd.Parameters.Add(“@CreationDate”,SqlDbType.DateTime);
cmd.Parameters.Add(“@Score”,SqlDbType.Int);
cmd.Parameters.Add(“@ViewCount”,SqlDbType.Int);
cmd.Parameters.Add(“@Body”,SqlDbType.NVarChar);
cmd.Parameters.Add(“@OwnerUserId”,SqlDbType.Int);
cmd.Parameters.Add(“@OwnerDisplayName”,SqlDbType.NVarChar,40);
Add(“@LastEditorUserId”,SqlDbType.Int);
cmd.Parameters.Add(“@LastEditDate”,SqlDbType.DateTime);
cmd.Parameters.Add(“@LastActivityDate”,SqlDbType.DateTime);
cmd.Parameters.Add(“@Title”,SqlDbType.NVarChar,250);
cmd.Parameters.Add(“@Tags”,SqlDbType.NVarChar,150);
cmd.Parameters.Add(“@AnswerCount”,SqlDbType.Int);
cmd.Parameters.Add(“@CommentCount”,SqlDbType.Int);
cmd.Parameters.Add(“@FavoriteCount”,SqlDbType.Int);
cmd.Parameters.Add(“@ClosedDate”,SqlDbType.DateTime);
cmd.Parameters.Add(“@ParentId”,SqlDbType.Int);
Trace.Write(DateTime.Now.ToString()+Environment.NewLine+“Reading”);
整数计数=0;
cn.Open();
while(rdr.Read())
{

如果(rdr.AttributeCount您只需将post文件拆分为2-3个文件,您仍然可以使用所使用的导入查询


例如,您可以通过使用EditPad打开文件(不要使用记事本+),因为文件太大,它会失败,而使用EditPad它会立即打开),只需剪切和粘贴几个文件(尽管它们是正确的XML,复制标题和结束标记).

我在谷歌上找到了同样的答案,但我没有使用express。LiraNuna不是说这是express的限制,他/她说这是几乎每一分贝的限制。分贝的总体大小不是限制因素,但栏目的大小是。提到“express Edition”是不相关的,显然模糊了解释。