I've got a problem connecting to my Database. I get this error
An attempt to attach an auto-named database for file C:\Users\Visual Studio 2013\WebSites\RegisterDb\App_Data\RegisterDb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Here is my web.config
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\RegisterDb.mdf;Integrated
Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
<add name="DdExamen2ConnectionString" connectionString="Data Source=
(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\RegisterDb.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
here is the Register.designer.cs
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="RegisterDb")]
public partial class RegistersDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new
AttributeMappingSource();
base(global::System.Configuration.ConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString, mappingSource)
I don't see what I am missing?
When I am looking at the Registers.dbml file, I saw the Connection : RegisterConnectionString(WebConfig) and the connection String is Data Source=(LocalDb).... I am pretty sure this is the problem. Anyone know how to recreate the ConnectionString ?
I saw 2 files in the web.config file for the connectionString ? What I did wrong?
You have used 2 connection strings. Remove one of them. Most probably the second connection string should b deleted. as you are working on your own machine and .\\SQLEXPRESS is simplest way to connect to your server. Remove the second one....
If you use a connection string in you application, use the same one for all connections to the same database.
remove
<add name="DdExamen2ConnectionString" connectionString="Data Source=
(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\RegisterDb.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.