Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have install the SQL server 2008 R2 & configure the server Mixed mode authentication with username = 'sa' & password = 'pw'
and my attachment .mdf file is located in d:\Test folder and service is running.

Now i connect the server2008 attachment .mdf file through coding but not connect. Error msg shown('An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)')

My code is below :->
--------------------
C#
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.\MSSQLEXPRESS;AttachDbFilename=D:\Test\db.mdf;
Integrated Security=True;Connect Timeout=30;User Instance=True";
con.Open();


How will i solve above problem???
Please help me any instruction......
Posted
Updated 20-Jun-12 21:37pm
v2

1 solution

Hi,

Make use of the ConnectionStrings Sction of Web.Config File.

<connectionstrings>
<add name="conString">
connectionString="Data Source=<machinename>\<sqlexpressinstancename>;
database=<your database>
Integrated Security=true">
</add>
<connectionstrings>


Regards,
Raghu...
 
Share this answer
 
v2
Comments
Member 7678194 21-Jun-12 5:13am    
Actually I want to connect attachment .mdf file in windows application for my sending problems.
Please help me proper answer...

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