简体   繁体   English

以…开头的标识符太长。 最大长度为128

[英]The identifier that starts with … is too long. Maximum length is 128

I have a problem. 我有个问题。 I try to create a database backup of a local database. 我尝试创建本地数据库的数据库备份。

When I start the program in VS everything is fine because path to database is less than 128 characters. 当我在VS中启动程序时,一切都很好,因为到数据库的路径少于128个字符。 However, when I publish and install the app, path is more than 128 characters in length and I get that error. 但是,当我发布并安装该应用程序时,路径的长度超过128个字符,并且出现该错误。

On the Internet I found two solutions: 在Internet上,我找到了两种解决方案:

  1. To use a single quote 使用单引号
  2. To set: SET QUOTED_IDENTIFIER OFF & SET ANSI_NULLS ON 设置: SET QUOTED_IDENTIFIER OFFSET ANSI_NULLS ON

but whichever combination I try, I cannot get it right. 但无论我尝试哪种组合,都无法正确完成。

Can anyone tell me how to get it right? 谁能告诉我如何正确处理?

My code: 我的代码:

internal void CreateDbBackup(string DbBackupPath)
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

    SqlCommand GetDataFile = new SqlCommand();
    GetDataFile.Connection = con;
    GetDataFile.CommandText = "select physical_name from sys.database_files where type = 0";

    con.Open();
    string YourDataFile = (string)GetDataFile.ExecuteScalar();
    con.Close();

    SqlCommand cmd = con.CreateCommand();
    cmd.CommandText = string.Format(@"BACKUP DATABASE [" + YourDataFile + "] TO  DISK = N'{0}' WITH  INIT ,  NOUNLOAD ,  NOSKIP ,  STATS = 10,  NOFORMAT", DbBackupPath);

    con.Open();
    cmd.ExecuteNonQuery();
    con.Close();
}

When you select select physical_name from sys.database_files , you get a bunch of file names. 当您select physical_name from sys.database_files选择select physical_name from sys.database_files ,会得到一堆文件名。 The syntax for BACKUP DATABASE requires, after DATABASE , not a file name, but a database name. 对于语法BACKUP DATABASE要求,经过DATABASE ,而不是一个文件名,但一个数据库名称。

Your file names include paths, and that causes the total path to be so long that it cannot be interpreted as a database name. 您的文件名包含路径,这会导致总路径太长而无法将其解释为数据库名称。 If the path were less long, you'd instead get the error that no database with that name could be found. 如果路径的长度较短,则会收到错误消息,即找不到该名称的数据库。 This would tell you more directly what you're doing wrong. 这将更直接地告诉您您在做什么错。

You should have the database name already from your connection string. 您应该已经从连接字符串中获得了数据库名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 指定的令牌太长。 最大长度为128个字符 - The token specified is too long. The maximum length is 128 characters 该文件解析为太长的路径。 最大长度为260个字符 - The file resolves to a path that is too long. The maximum length is 260 characters System.UriFormatException:'无效的URI:Uri方案太长。 - System.UriFormatException: 'Invalid URI: The Uri scheme is too long.' 414.请求的URL太长。 网 - 414. The request URL is too long. asp.net Selenium C# drive.PageSource - '太长,或指定路径的组件太长。 - Selenium C# drive.PageSource - 'is too long, or a component of the specified path is too long.' C#/ CLI标识符的最大长度是多少? - What is the maximum length of a C#/CLI identifier? 我正在使用WPF TextBlock,但是当文本太长时,文本会被切断。 是否有AutoScroll功能? - I'm using a WPF TextBlock but then text gets cut off when it's too long. Is there an AutoScroll feature? 指定的路径,文件名或两者都太长。 C#Azure聊天机器人错误 - The specified path, file name, or both are too long. C# Azure Chat bot error HTTP错误414.请求URL太长。 asp.net - HTTP Error 414. The request URL is too long. asp.net 字符串参数太长。 从数据库到Word模板检索数据 - String parameter too long. retriving data from database to word template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM