我可以在SQL中插入一个大字符串hacing unicode吗? [英] Can I insert a large string hacing unicode in SQL ?

查看:86
本文介绍了我可以在SQL中插入一个大字符串hacing unicode吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



将大字符串传递给SQL查询时Inertion失败



String如下:



Hi All,

Inertion failed to while passing a large string to SQL query

String as follows:

%PDF-1.6
%����
69 0 obj
<</Linearized 1/L 777207/O 71/E 86298/N 13/T 776799/H [ 447 172]>>
endobj
75 0 obj
<</DecodeParms<</Columns 3/Predictor 12>>/Filter/FlateDecode/ID





它有大约7万卢比这样的字符。我是否可以使用插入查询插入SQL?

这是我的代码如下:



its having around 7 lakhs charecters like this . Whether I can insert into SQL using insert query ?
Here is my code as follows:

string readText = File.ReadAllText(@"D:\olefy001.txt");
           SqlCommand cmd = new SqlCommand("insert into FileContent values(" + readText + ")", con);
           cmd.ExecuteNonQuery();





我的尝试:



使用批量插入其工作!但是我必须将它作为字符串变量传递给插入查询才有可能吗?



使用批量插入插入后选择查询是不是取所有元素做什么?



What I have tried:

Using Bulk insert its working ! But I have to pass it as string variable inside insert query is it possile ?

Select query is not fetching all elements after inserting using bulk insert what to do ?

推荐答案

SqlCommand cmd = new SqlCommand("insert into FileContent values(" + readText + ")", con);



not a 解决你的问题,但你遇到的另一个问题

永远不要通过连接字符串来构建SQL查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

按示例进行SQL注入攻击 [ ^ ]

PHP:SQL注入 - 手册 [ ^ ]

SQL注入预防备忘单 - OWASP [ ^ ]


Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]


简单:

Simple:
string readText = File.ReadAllText(@"D:\olefy001.txt");
using (SqlCommand cmd = new SqlCommand("insert into FileContent values (@ReadText)", con))
{
    cmd.Parameters.AddWithValue("@ReadText", readText);
    cmd.ExecuteNonQuery();
}



你想知道关于SQL注入的一切(但不敢问)|特洛伊亨特 [ ^ ]

如何在没有技术术语的情况下解释SQL注入? |信息安全堆栈交换 [ ^ ]

查询参数化备忘单| OWASP [ ^ ]


Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]


这篇关于我可以在SQL中插入一个大字符串hacing unicode吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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