No se puede conectar a SQL Server localmente

I am getting the following exception when I am trying to connect to a web service

System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file DatabaseName.mdb failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

La cadena de conexión que estoy usando es:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|WS_Assignment.mdb;uid=Admin;pwd=" 
providerName="System.Data.OleDb"

I am trying to access SQL Server on local system.

I have gone through a lot of articles and followed all the different methods. But I got no solution.

¿Puede alguien ayudarme?

preguntado el 05 de mayo de 13 a las 19:05

.mdb is MS de la máquina - no SQL Server .... -

I have a ms access database. how do i make it into a .mdf database to access on SQL server? -

Create your SQL Server database (in e.g. Management Studio), and then use e.g. SQL Server Integration Services (the "Data Import" wizard) to import your Access data into SQL Server -

Thanks marc_s I think what you pointed out was helpful -

3 Respuestas

Before Question was EDITED:

are you deploying on a web server , instead of your localhost. If thats the case you need to publish the sql script in Server DB as servers dont allow attachDB file in your deployment and if thats the case then your problem is solved.

Después de la actualización you can always try with fullpath and yes you need OLEDB call not sql make sure thats not the case with your .cs code

Correction in your question:

i am trying to access SQL server On local system

: i dont see how you can do that with .mdb file; even if thats not the case make sure sql services are running properly in your system go to->start button->program files->microsoft sql server yourversion-> configuration manager-> check running services.

contestado el 05 de mayo de 13 a las 19:05

En su Solution Explorer, haga clic en "Show All Files". entonces ve a tu App_Data carpeta y eliminar WS_assignment.mdb y luego ejecute su aplicación.

Also, your provider is wrong

providerName="System.Data.SqlClient" is the right one.

Secondly, your database name should end in .mdf or .sdf para SQL Server.

So, your connection string will become:

 <connectionStrings>
    <add name="ConnectionStringName"
     connectionString="Data Source=|DataDirectory|WS_Assignment.sdf"
     providerName="System.Data.SqlClient"/>
  </connectionStrings> 

contestado el 05 de mayo de 13 a las 19:05

También por .sdf (= SQL Server Compact) you will need to use a different providerName=.... value! The one you're giving is only for the ser completados SQL Server version (no for SQL Server CE) - marc_s

Mira esto.
http://msdn.microsoft.com/en-IN/library/5ybdbtte%28v=vs.71%29.aspx
using Access requires Sistema.Datos.OleDb bibliotecas

contestado el 05 de mayo de 13 a las 20:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.