Reputation: 433
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!!!
Upvotes: 0
Views: 923
Reputation: 1669
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
Upvotes: 1