A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

alattin (16999) 9 yıl önce sordu

Asp.Net uygulamasında lokal bir MS SQL veritabanına,bir .MDF dosyasına bağlanmak istediğimde aşağıdaki gibi bir hata alıyorum:

An attempt to attach an auto-named database for file C:\Users\bilgisayar\Documents\Visual Studio 2013\Projects\CRM.UI\App_Data\Database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Asp.Net ile yerel bir veritabanına bağlanırken alınan A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. hatasının çözümü nedir?

Toplam 1 cevap


alattin (16999) 9 yıl önce cevapladı

Asp.Net ile yerel bir veritabanına bağlantı yaparken alınan bu hatanın sebebi hatalı bir bağlantı cümlesi kullanılmasıdır.

Asp.Net ile yerel bir veritabanına bağlanırken alınan A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. hatasının çözümü için bağlantı cümlenizi (connection string) aşağıdaki gibi  yapılandırmalısınız:

Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=|DataDirectory|Database.mdf;

Web.config içindeki bağlantu cümleniz şu şekilde olmalıdır:

 <connectionStrings>
    <add name="CMSDbContext"
         providerName="System.Data.SqlClient"
         connectionString="Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=|DataDirectory|Database.mdf;"/>  
  </connectionStrings>

Bu bağlantı ifadesi ile mdf dosyalarını rahatlıkla uygulamanızda kullanabilirsiniz.