Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to do some sql code run in my webservice in c#

the code is just
C#
[WebMethod]

 public void GetCustomers() 
    {
         SqlConnection MyConn = new SqlConnection("Data Source=./SQLEXPRESS;AttachDbFilename=C:/Documents and Settings/Administrator/My Documents/Visual Studio 2008/Projects/WebService2/WebService2/App_Data/Database1.mdf;Integrated Security=True;User Instance=True");  
        MyConn.Open();
          SqlCommand cmd = new SqlCommand();   
       cmd.Connection = MyConn;   
       cmd.CommandText = "delete from t1 where name='1'"; 

        cmd.ExecuteNonQuery();    
 }


now i got error like

System.Data.SqlClient.SqlException: 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)
Posted

try with AttachDbFilename property.
see here
Link[^]

Thanks
--RA
 
Share this answer
 
Comments
thatraja 27-Jan-12 10:58am    
5!
Rajesh Anuhya 27-Jan-12 21:35pm    
Thanks Raja
--RA
In ASP.Net, you should not provide an absolute address string for your database.
Have a look here[^] at how you would be setting up a database connection in ASP.Net.
This[^] describes using connection strings in the config file and should help you get started as well.
 
Share this answer
 
Comments
thatraja 27-Jan-12 10:58am    
5!
Abhinav S 27-Jan-12 10:59am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900