sql连接字符串错误'无法识别的转义序列' [英] sql connection string error 'Unrecognized escape sequence'

查看:358
本文介绍了sql连接字符串错误'无法识别的转义序列'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void btnsv_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=tubd_data;Data Source=TIMY\SQLEXPRESS");
           
    try
    {
        con.Open();
        statusStrip1.Text="Connection Succesfull !!!";

        SqlCommand cmd = con.CreateCommand();

        cmd.CommandText="Insert into must_first [invoice_no], [date], [name], [total], [total_iv] values ('" + invo_no.Text + "','" + bill_datetxt.Text + "','" + txtname.Text + "','" + txttot.Text + "','" + txtvatinclu.Text + "')";
        con.Close();
        try
        {
            cmd.ExecuteNonQuery();
            statusStrip1.Text="Record Updated!!!";
        }
        catch(Exception)
        {
            statusStrip1.Text="Record Update Error!!!";
        }
    }
    catch(Exception)
    {
        statusStrip1.Text="Connection Fail !!!";
    }
}

推荐答案

Hello Abhishek,



尝试在SQLEXPRESS之前添加额外的''\''。请参阅好文章 [ ^ ]了解更多字符串转义。



问候,
Hello Abhishek,

Try adding an extra ''\'' before SQLEXPRESS. Please refer to a nice article[^] here on CodeProject to learn more String escaping.

Regards,


SqlConnection con = new SqlConnection(Provider = SQLOLEDB.1; Integrated Security = SSPI;持久安全信息=假;初始目录= tubd_data;数据源= TIMY \SQLEXPRESS);





//添加提供者之前的@符号。它会工作正常。 @ --->转义字符

//如果你不使用@

SqlConnection con =当你在连接中使用\符号时会遇到问题new SqlConnection(@Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info = False; Initial Catalog = tubd_data; Data Source = TIMY \ SQLEXPRESS);
SqlConnection con = new SqlConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=tubd_data;Data Source=TIMY\SQLEXPRESS");


//Add @ symbol before Provider. It will work fine. @--->Escape characters
//When you are using \ symbol in connection that time you will face problem if you are not using @
SqlConnection con = new SqlConnection(@"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=tubd_data;Data Source=TIMY\SQLEXPRESS");


这篇关于sql连接字符串错误'无法识别的转义序列'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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