Monday, May 28, 2012

[Action Script] Problem with connection string in visual studio 2010!!!!! May,2012

hello
i am working on a website..using ASP.net 4.0 and C#.
everything with the designing and layouts is done so i shifted my focus on the database thing and the first day has been the longest yet..
i also have the MS SQL Management server 2008 R2 installed as windows authentication but im not using that.
I am using the inbuilt database service in the visual studio 2010.
what i did was that..
First i created a database by going to "ADD NEW ITEM" and then selecting the "SQL DATABASE SERVER" , inamed it DNS.
the database got created fine. I added some tables and content to it. I the dragged the table in my content place holder and the gridview was fine..when i run the page, the data is displayed fine in the gridview.
The problem is that i am not able to get data into the database..the connection srting seems wrong, my connection string is

Code: SqlConnection con = new SqlConnection("Server=VISHAL-PC;Database=DNS;Integrated Security=True;");Also in the properties of my database connection string is different..here it is

Code: Data Source=.\SQLEXPRESS;AttachDbFilename="E:\Programing\Projects\DNS Site 2\App_Data\DNS.mdf";Integrated Security=True;User Instance=Truehere the server is displayed ".\SQLEXPRESS" but if i write that in my connection string then it shows a red line under the ".\" part and also in the file path.
Even if i dont use the file path and give the database name DNS and server name as SQLEXPRESS then also error occurs at my connection object con.

This is the error i get
Code: 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)he error is shown here:
Code: SqlConnection con = new SqlConnection("Server=VISHAL-PC;Database=DNS;Integrated Security=True;");
    SqlDataAdapter da;
    DataSet ds = new DataSet();


    protected void Page_Load(object sender, EventArgs e)
    {

    }
   
   
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds1 = new DataSet();
        SqlCommand cmd = new SqlCommand("Insert into Registration values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" +        TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text +            "','" + TextBox12.Text + "','" + TextBox13.Text + "','" + TextBox14.Text + "',),con");
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
       
        Response.Write("Data Saved Sucessfully");
       


    }..Here is the code from my web.config <connectionstring>
Code: <connectionStrings>
  <add name="DNSConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DNS.mdf;Integrated Security=True;User Instance=True"
  providerName="System.Data.SqlClient" />
 </connectionStrings>im unable to get my connection string..please help me guys..i just have 2-3 days!!
Problem with connection string in visual studio 2010!!!!!

Related Post



0 comments: