Invalid value for key attachdbfilename C# Identity Server Connection String - c#

I am trying to create the identity tables in my server database. However, I keep getting an "Invalid value for key 'attachdbfilename'" error.
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=den1.mssql.gear.host;Initial Catalog=groceryapp;User Id=appID;Password=password;AttachDbFilename=|DataDirectory|\UsersDB.mdf;"
providerName="System.Data.SqlClient" />
<add name="appID"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=den1.mssql.gear.host;initial catalog=groceryapp;user id=appID;password=password;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
I am following the tutorial of this video.. https://www.youtube.com/watch?v=Y02ccL4-_K4
EDIT
I changed the |DataDirectory| to my physical path, but now I get permission issues with SQL Server:
ExceptionMessage=CREATE DATABASE permission denied in database 'master'.
Cannot attach the file 'PHYSICAL_PATH\App_Data\UsersDB.mdf' as database 'testDatabase'.

First:
You can try to change that with the physical path of your Users.mdf
Second:
Try to check if user appID has a right create table. If not, give it privilege to create one.

Related

Get SQL Connection error while using Web Service with local SQL Server database

I'm setting up a web service, I wanted to use the local database so I created a local SQL Server database in this project. The web service runs just fine on localhost, but the problem when I invoke a method to Load data from the local database on this project, I'm getting an error:
System.Data.SqlClient.SqlException:
An attempt to attach an auto-named database for file C:\Program Files (x86)\IIS Express\TourTravelDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
TourTravelDB.mdf is my local database
I've added a connection string in my web.config but it's still not working.
Here is my connection string.
<connectionStrings>
<add name="CS"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\TourTravelDB.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
I've also tried to move my database to the IIS Express directory, it works but when run it from another computer, I have to move the database again.
Does anyone have an idea how to solve this?
This may help you..
Add "User Instance=True;" in your connection string.
<connectionStrings>
<add name="aspnet_staterKits_Test_TimeTracker"
connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
</connectionStrings>
if doesn't work then try out the below links..
forums.asp.net
codeproject.com
Already existing thread in stack overflow

EF 6 "Unable to load the specified metadata resource" -- but I'm not using edmx

Sorry if this has been asked, but I've gone through all of the other posts I can find and everyone seems to be using an EDMX, and not a "production" database.
I get the following error:
System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource
when attempting to access my application. My connection string is as follows:
<add name="FormAssemblyEntities" connectionString="metadata=res://*/Models.Entities.FormAssembly.csdl|res://*/Models.Entities.FormAssembly.ssdl|res://*/Models.Entities.FormAssembly.msl;provider=System.Data.SqlClient;provider connection string="data source=server\instance;initial catalog=dbname;user id=userid;password=password;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
This works perfectly if I am running it locally and it connects to the edmx with the following connection string, but as soon as I put it on our UAT server and point it to the database, I get that error.
<add name="FormAssemblyEntities" connectionString="Data Source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\FormAssembly.mdf;Initial Catalog=FormAssembly;Integrated Security=SSPI;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
I really have no idea where to start. The database appears up to date, the user has access, and the server has access to the SQL server.
I have also tried replacing the res://*/ with res://FormAssembly/ and res://FormAssembly.dll/, but the former results in the same error, and the latter says the dll can't be found (the DLL is in the bin directory).
Any help would be appreciated.
Thanks,
Travis
In my case, the metadata part of my connection string was malformed.
The following connection string worked in my case:
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string="data source=(local);initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>

Login failed while connecting to database

I have created WPF application which has MDF file. When I added MDF file to my solutions folder It automatically created a connection string for me
<add name="Connection"
connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=C:\Users\Public\Desktop\MyDatabase.mdf;Integrated Security=True;"
providerName="System.Data.SqlClient" />
I Deployed my application using SQL Server Compact (as described here). But When I run my Application I am getting exception
Cannot open database "C:\Users\Public\Desktop\MyDatabase.mdf" requested by the login. The login failed.
Login failed for user 'MY-PC\NAME'.
I am using Windows Authentication for my SQL Server
change your connection string as follows:
<add name="Connection"
connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=C:\Users\Public\Desktop\MyDatabase.mdf;persist security info=True;Integrated Security=SSPI;"providerName="System.Data.SqlClient" />

An attempt to attach an auto-named database for file xxxx failed

I have a database file (FinanceDB.mdf) stored on the local harddrive. I can connect to the file, but when I execute queries to it through C#, I get the following error:
An attempt to attach an auto-named database for file F:\IT7x01Project\App_Data\FinanceDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
I have set the permissions for everyone on the file to full access which I thought may be part of the problem, but it turns out that its not (unless there is more to it than just setting the permissions).
This is the connection string:
<add name="FinanceDBConnectionString1" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=F:\IT7x01Project\App_Data\FinanceDB.mdf;Integrated Security=True;" providerName="System.Data.SqlClient"/>
Any help with this would be appreciated.
try to create connection string in this format
<add name="Connec" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=C:\USERS\dL\DESKTOP\DATABASE\MYSHOP.MDF;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient"/>
(or)
Try setting the User Instance property in your connection string to true.
User Instance=True
Also just to be sure check again weather your database server already contain a database with the same name.
<add name="Connections" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
add in we.config file

Cannot Access To ASP.NET Configuration Tool

When I want to access to ASP.NET Configuration Tool it gives me the following error message:
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database.
What can I do. Is there any configuration which I should set before I can access or ?
I am using ASP.Net MVC4 Project with build in connection string.
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-AccountPortal-20131128183241;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-AccountPortal-20131128183241.mdf" providerName="System.Data.SqlClient" />
you should access your connection string from web.config file before proceeding further.
web.config file :
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-AccountPortal-20131128183241;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-AccountPortal-20131128183241.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
from code : access connection string which is in web.config file
string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

Categories

Resources