none
solution for runtime error in visual studio 2012 while connecting to sqlserver 2012.

    Question

  • Hi,

    I have installed vs2012,sqlserver 2012 and sql management studio 2012 on my dell windows 8 laptop.

    sqlmangement studio successfully connected to server . Then i created a demo application for inserting data into the server from text box. i'm able to connect to database but when i run the application an error occurring as bellow

    "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"

    when i opened sql server configuration management tool, i find that sql server agent status  as stopped, and error occurring while i try to start sql server agent.

    how can i fix this problemm...

    plzzz  help meee

    thankss in advance

    • Moved by Darren GosbellMVP Monday, November 04, 2013 2:24 AM This is a question about the relational engine
    Saturday, November 02, 2013 7:16 PM

Answers

  • when i use backslash (\) in connention stringg ,,  a compile time error occurss as  '"unrecognizes escape sequence"..

    Ups, sorry, you are using C#; here you have to double quote the backslash =>

    SqlConnection conn=new SqlConnection("Data Source=ASAD\\SQLEXPRESS;Initial Catalog=dsondb;Integrated Security=True");

    or you have to start the string with the @ sign =>

    SqlConnection conn=new SqlConnection(@"Data Source=ASAD\SQLEXPRESS;Initial Catalog=dsondb;Integrated Security=True");


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    • Marked as answer by joohhn Wednesday, November 06, 2013 4:43 PM
    Wednesday, November 06, 2013 10:24 AM

All replies

  • Hi, it sounds like there are a couple questions here. 

    What edition of SQL Server 2012 did you install?  If it was Express, then the Agent service not starting is expected since Express edition does not include Agent.  You can still connect to the engine and run your application without this service.

    For the connection issue, are you running the application from the local machine or from a remote machine?  Can you clarify what you mean about being able to connect to the database, but getting the connection error when you run the application?  The error message above is hit when a connection is not established, often because the TCP/IP protocol is not enabled through SQL Server Configuration Manager.

    Thanks,
    Sam Lester (MSFT)

     

    http://blogs.msdn.com/b/samlester

    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

    Tuesday, November 05, 2013 9:07 AM
  • Hello,

    How does your connection string look like; may you can post it here?


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Tuesday, November 05, 2013 6:48 PM
  • sir this is my code

            private void button1_Click(object sender, EventArgs e)
            {
                SqlConnection conn=new SqlConnection("Data Source=ASAD/SQLEXPRESS;Initial Catalog=dsondb;Integrated Security=True");
                SqlCommand cmd=new SqlCommand("insert into tabreg values('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"')",conn);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }

    Wednesday, November 06, 2013 7:08 AM
  • sir,

    im using microsoft visual studio2012 ultimate.

    my application is running on my local machine.

    I mean by that , is  successfully include database in server explorer by selecting  tools->connect to database and select the proper database , and test connection is also succeed.

    my code

     private void button1_Click(object sender, EventArgs e)
            {
                SqlConnection conn=new SqlConnection("Data Source=ASAD/SQLEXPRESS;Initial Catalog=dsondb;Integrated Security=True");
                SqlCommand cmd=new SqlCommand("insert into tabreg values('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"')",conn);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }

    Wednesday, November 06, 2013 7:40 AM
  • SqlConnection conn=new SqlConnection("Data Source=ASAD/SQLEXPRESS;Initial Catalog=dsondb;Integrated Security=True");

    The data source is wrong, machine and instance name must be separated with a backslash \, not with a slash / =>

    SqlConnection conn=new SqlConnection("Data Source=ASAD\SQLEXPRESS;Initial Catalog=dsondb;Integrated Security=True");


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Wednesday, November 06, 2013 7:49 AM
  • when i use backslash (\) in connention stringg ,,  a compile time error occurss as  '"unrecognizes escape sequence"..

     sir,  I had work with sqlserver , so always u would use / instead of \.

    help me sir..

    whether its need to start sqlserver agent in order to run the application successfully.??? 

    i had installed and used the thess softwares before 4 timess . only difference now is windows8 dell system and user having a password too...

    • Edited by joohhn Wednesday, November 06, 2013 10:22 AM
    Wednesday, November 06, 2013 10:09 AM
  • sir,

    im using microsoft visual studio2012 ultimate.

    my application is running on my local machine.

    I mean by that , is  successfully include database in server explorer by selecting  tools->connect to database and select the proper database , and test connection is also succeed.

    my code

     private void button1_Click(object sender, EventArgs e)
            {
                SqlConnection conn=new SqlConnection("Data Source=ASAD/SQLEXPRESS;Initial Catalog=dsondb;Integrated Security=True");
                SqlCommand cmd=new SqlCommand("insert into tabreg values('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"')",conn);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }

    Wednesday, November 06, 2013 10:11 AM
  • when i use backslash (\) in connention stringg ,,  a compile time error occurss as  '"unrecognizes escape sequence"..

    Ups, sorry, you are using C#; here you have to double quote the backslash =>

    SqlConnection conn=new SqlConnection("Data Source=ASAD\\SQLEXPRESS;Initial Catalog=dsondb;Integrated Security=True");

    or you have to start the string with the @ sign =>

    SqlConnection conn=new SqlConnection(@"Data Source=ASAD\SQLEXPRESS;Initial Catalog=dsondb;Integrated Security=True");


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    • Marked as answer by joohhn Wednesday, November 06, 2013 4:43 PM
    Wednesday, November 06, 2013 10:24 AM
  • thankss sirr

    i forgot that..

    it worksss  

    Wednesday, November 06, 2013 4:44 PM
  • Your are welcome; please feel free to come back again if you have any further issue/question.

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Wednesday, November 06, 2013 4:47 PM