Question

ok my ASP.net website is running as long I do not use the database. I guess the problem is that I do not really understand the setup of the connectionstring and struggle do find the correct answer.

My connection string looks like this: "ConnectionStrings" "Add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=aspnetdb;AttachDbFilename=|DataDirectory|\aspnetdb.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient" /" "add name="ApplicationServices" connectionString="Data source=.;Integrated Security=True;Initial Catalog=aspnetdb" /" "/connectionStrings"

===> I had to change the code as it wouldn't display otherwise (sorry)

When I run the application and want to login on localhost I get the following error: (website is on the server versus SQL is on the C drive installed):

Database 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\aspnetdb.mdf' already exists. Choose a different database name. Cannot attach the file 'S:\H-L\legaldocsnsw\WebSite1\App_Data\aspnetdb.mdf' as database 'aspnetdb'.

On the internet there is a database master and my database I created CID05220_aspnetdb: CREATE DATABASE permission denied in database 'master'. Cannot attach the file 'C:\inetpub\vhosts\legaldocsnsw.com.au\httpdocs\App_Data\aspnetdb.mdf' as database 'aspnetdb'.

How do I have to change the connection string to access these either locally or on the net. Could someone please help and maybe even explain what I am doing wrong please?

Kind Regards, Rene

Was it helpful?

Solution

Do you want to use a database that is permanently attached to the SQL Server instance or do you want to attach an MDF file at run time? If you want to do the former then get rid of the AttachDbFilename attribute in your connection string. If you want to do the former then you will need a SQL Server Express instance or LocalDB installed on the same machine as the application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top