1 Replies - 703 Views - Last Post: 04 October 2012 - 07:38 AM Rate Topic: -----

#1 chenaz   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-November 11

connection issue

Posted 04 October 2012 - 07:23 AM

hi guys ,
as i mentioned, i had problem connecting to database. whenever i click run, error will occurse at my datasourcesaying(Error 1 Unrecognized escape sequence ) which is at this line
ata Source=AIZHONG-LAPTOP\SQLEXPRESS;Initial Catalog=test11;Integrated Security=True")

if i remove the \SQLexpress
another error occurred when i click the button. saying ( a network related instance. check the connection name or blablabla.)
i copy the orginal name from the database propertise which i don think is wrong. anyone is kind enough to enlighten me?

 protected void Button1_Click(object sender, EventArgs e)
            SqlConnection conn = new SqlConnection("Data Source=AIZHONG-LAPTOP\SQLEXPRESS;Initial Catalog=test11;Integrated Security=True");
            SqlCommand cmd;
            SqlDataReader dr;
  cmd=new SqlCommand("select * from logg where name='"+ TextBox1.Text +"'and pass='"+TextBox2.Text +"'",conn);
        dr= cmd.ExecuteReader();

            if (dr.Read ())
              Label3.Text="u are logged in";

Is This A Good Question/Topic? 0
  • +

Replies To: connection issue

#2 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon

Reputation: 5103
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: connection issue

Posted 04 October 2012 - 07:38 AM

That's because \ begins an escape sequence. \n is new line, \t is tab, \u+#### is a unicode character (if you replace the # with numbers). There are two ways to get around escape sequences: you can add another \ to your string. \\ escapes to \

Also, you can prefix your string with the @ character. That makes a string a "verbatim string", meaning that there will be no escaping performed.

Two examples:

string path = "c:\\dev\\test.txt";
string path2 = @"c:\dev\test.txt";

That should tell you enough to fix your code.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1