0

I downloaded a project from the web with its database. I run the project and add its database to tab server on VS 2008 Sp1 and have SQl server 2008.

But when I copy a new connection string to the program, I get the following error message:

Unrecognized escape sequence

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace AzmongirSource
{
class cl 

   {

    static public  string idstudent;
    static public string userteacher;
    static public string nameazmon;
    static public string codeazmon;

    static public string azmon_typ;
    static public string azmon_for_test_type;
    static public string time_limit;
    static public string tedade_soalat;

    static public  SqlConnection connection = new SqlConnection();
    static public  SqlCommand command = new SqlCommand();
    static public  SqlDataReader reader;
    static public  int truequestion = 0, falsequestion = 0, noquestion = 0;


    static public  void creatconnection()
    {

        connection.Close();
        connection.ConnectionString = "Data Source=WINXPX86-BE;AttachDbFilename=D:\payegah\azmoongir_data.MDF;Integrated Security=True";
        connection.Open();
        command.Connection = connection;
    }
   static public  DataTable StudentList()
    {
        creatconnection();
        string query = "Select idstu as[شماره دانشجویی],namestu as [نام],familystu as [نام خانوادگی],standardcode as [کداستاندارد],reshte as [رشته] from tbl_student";
        SqlDataAdapter da = new SqlDataAdapter(query, cl.connection);
        DataTable dtt = new DataTable();
        da.Fill(dtt);
        connection.Close();
        return dtt;

    }

}
}

3 Answers 3

3

You need to escape backslashes in your connection string, or use @

connection.ConnectionString = @"Data Source=WINXPX86-BE;AttachDbFilename=D:\payegah\azmoongir_data.MDF;Integrated Security=True";

Documentation: Escape Sequences

Sign up to request clarification or add additional context in comments.

Comments

1

By default \ is considered to be an escape character. To avoid that add @ before your connecting string.like

connection.ConnectionString = @"Data Source=WINXPX86-BE;AttachDbFilename=D:\payegah\azmoongir_data.MDF;Integrated Security=True";

Comments

0

Add @ symbol before your connection string

@--->Escape characters

connection.ConnectionString = @"Data Source=WINXPX86-BE;AttachDbFilename=D:\payegah\azmoongir_data.MDF;Integrated Security=True";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.