0

I am unable to connect to my database to insert data into it.

protected void Submit_Click(object sender, EventArgs e)
{
    using(SqlConnection sc = new SqlConnection()) {
    sc.ConnectionString = "Data Source=localhost;Initial Catalog=DrugDB;Integrated Security=True";
    sc.Open();
    using (SqlCommand com = sc.CreateCommand()) {
        com.CommandText = "insert into Drug(DrugID,DrugName)values(@txtDrugID,@DrugName)";
       com.Parameters.Add("@DrugID", SqlDbType.VarChar, 10).Value=TBDrugId.Text;
       com.Parameters.Add("@DrugName", SqlDbType.VarChar, 10).Value=TBDrugName.Text;
}
    }

This is the error I get:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)

This in in my webconfig:

<connectionStrings>
<add name="DrugDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=DrugDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
<add name="ApplicationServices" connectionString="data source=SOIS-PC\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=testdatabase.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="ConStr" connectionString="Data Source=SOIS-PC\SQLEXPRESS;AttachDbFilename=DrugDB.mdf; Integrated Security=True"/>
</connectionStrings>

Plase help!!!

4
  • codeproject.com/Questions/356619/… Commented Mar 18, 2014 at 5:03
  • Are you sure the user is allowed to connect to the server ? Can you try connecting to the DB using SQL management studio ? Commented Mar 18, 2014 at 5:03
  • It is still erroring out! <add name="ConStr" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Users\SOIS\Documents\Visual Studio 2010\WebSites\DummyPharmacy\App_Data\DrugDB.mdf"; Integrated Security=True;User Instance=True"/> </connectionStrings> It says missing required whitespace Expecting end tag /add Commented Mar 18, 2014 at 5:07
  • I created the DB using Visual Studio. I cannot attach the DB through my SQL server. I do not know why. Commented Mar 18, 2014 at 5:10

1 Answer 1

1

It could be your SQL Server is configured to use NAMED PIPES instead of TCP/IP. Connect using TCP/IP, or use the SQL Server Configuration Manager to enable remote connections using named pipes. more info here

Also here is another post

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

1 Comment

Tried that. Restarting now.

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.