I am at a loss as to how to fix this issue.
When running my MVC application and trying to access the user database I get the dreaded SQL Network Interfaces, error: 50.
I can see all the data in the Server Explorer in VS, but I can never get the application to see it.
I have spent sometime reading this;
SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance 9
I have renamed and created new databases.
I have added/changed the entry in the applicationHost.config file.
I have changed the connection string every which way from Sunday.
I just cant figure it out.
Here is my connection string in the Webconfig file.
<add name="UserConnection" connectionString="Data Source=(LocalDB)\V11.0;AttachDbFilename=|DataDirectory|\ShopUsers.mdf;Initial Catalog=ShopUsers;Integrated Security=True" providerName="System.Data.SqlClient" />
I even downloaded and ran the ContosoUniversity sample code to see if it works, and it does.
Here is that connection string, (that works fine)
<add name="SchoolContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=ContosoUniversity1;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
It seems there is something amiss between IIS and the db Server.
Any new ideas would be greatly appreciated.
Oh ya, I did have this working just fine on my old PC.
Seems like you have the database file created already (I suspect you do because of the following segment: AttachDbFilename=|DataDirectory|\ShopUsers.mdf;). If so, then ensure you have it in the same folder beneath your project as the original one on your old PC, usually the |DataDirectory| stands for App_Data (look the answer to this question).
If, you need a brand new database however, you should have tried the following connection string:
<add name="UserConnection" connectionString="Data Source=(localdb)\v11.0\ShopUsers;Initial Catalog=ShopUsers;Integrated Security=True" providerName="System.Data.SqlClient" />
This will create the database for you.
Related
I am writing Integration tests for a WPF application and I'm using a local database that is placed inside the solution for integration testing and this database has data inside it.
When I read data from this database after connecting it to SQL Server, it returns valid data, but once I go back to the application, add its connection string and try to get data, the code returns an empty set. I'm on a tight deadline and I don't know why this is happening.
Any help will be greatly appreciated.
Simple code is:
var xsystem = context.Species.ToList();
My connection string is:
<add name="MaxDatabase"
connectionString="Data Source=(LocalDb)\ProjectsV13;Initial Catalog=Catalog=MaxLocalEmbeded;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
Just replace your connection string with this below code.
Also remove "catalog=catalog" from your connection.
<add name="MaxDatabase" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=MaxLocalEmbeded;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MaxLocalEmbeded.mdf" providerName="System.Data.SqlClient" />
I am learning basics of MVC. And forgive me If I am not able to ask question properly because I am not aware of various technical terms. Anyways I am trying build one simple page where I will have two tables courses and Instructors. I am able to do most of the stuff and it seems to be working. Also I do have a solution given by my faculty of the same problem. When I am comparing my solution and faculty solution then in the web.config file of the actual solution given by my faculty I see something like
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcCRUDwithSQL-20140217025002.mdf;Initial Catalog=aspnet-MvcCRUDwithSQL-20140217025002;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="CourseContext" connectionString="Data Source=(localdb)\v11.0; Initial Catalog=CourseContext-20140217145250; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|CourseContext-20140217145250.mdf"
providerName="System.Data.SqlClient" />
</connectionStrings>
Where as in my solution that I just have one add name tag. I don't know why the another tag did not get created automatically. Or do I need to add that tag manually.
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication9-20150313042831.mdf;Initial Catalog=aspnet-WebApplication9-20150313042831;Integrated Security=True" providerName="System.Data.SqlClient" />
Have I done something wrong that the connection string related to CourseContext did not get generated automatically. Or we need to add for CourseContext manually? Please help me. Since most of the files and its content are generated automatically I must have done something wrong that connection string pertaining to CourseContext did not get generated.
Use the steps below to generate the connection string via visual studio server explorer
Click on server explorer
Connect to database
Choose server name from dropdown
Choose your authentication type
Select your database from dropdown
Test connection
Copy the connection string from the properties and paste in your web.config
Also take a note of #Guffa answer, he's got a very good point
You don't need one connection for each table, you only need one connection for each database. A database can contain many tables (the project I'm working on right now has 9 tables, and that is a really small project).
The Visual Studio template starts out with a default connection string, but no database. It looks like it's that connection string that is still left in the solution.
I've created project to read from MSSQL DB and display some data. VS's wizards created connection string like the following:
<add name="SomeContext" connectionString="data source=xxx.xxx.xxx.xxx\_name,port;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
When I tried to deploy application to the real web server I changed connection string to use faceless DB account:
<add name="SomeContext" connectionString="data source=xxx.xxx.xxx.xxx\_name,port;User Id=userid;Password=password; MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
It looks like EF thinks that there some migration needed and tries to execute a lot of meaningless operations including attempts to execute SQL expressions with schema creating.
I have no write permissions on this DB server and I don't see any reasons to allow EF change DB structure.
So I'm completely lost there. What is the proper way to change authorization methods without changing on DB side?
Try to change connection string to production in VS project, then use Update-Database via Package Manager Console.
Pretty strange for me but the root of the issue was in default "initial catalog". It was stored somewhere for connection with integrated security but when I changed authorization method default was broken. As soon I defined initial catalog it was fixed.
I'm trying to implement basic three tier architecture with mvc 3. but getting an error while running the solution ( showing no error while building the solution). The organization of my projects & error message can be seen in the attached image.
Please help.
OK guys, This is an update for.
As specified by some comments, I copied the original connection string from app.config to my web.config file & getting this error as shown in the image.
I tried to search a lot but no clue! Any help will be highly appropriated.
#Maarten is right. you always copied the normal connection string (that is a part of entity-connection string). you need to copy the entire connection string that was generated in your App.config file in Data layer and paste it in the web.config file in your presentation layer. the entity-connection string like as :
<add name="NorthwindEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.\sqlexpress;initial catalog=Northwind;persist security info=True;user id=sa;password=Blister01;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
don't copy-paste it, it is just a sample
The connection string you've copied is a normal connection string. You are using an edmx file which means you need an entity-connection string.
You need to copy the entity-connectionstring into the web.config. You can find the EF-connectionstring in the app.config file in the Data layer where EF added it for you.
you just add connection string connectionStrings section in web.config in Presentation layer!
See this image
EDITED: try with this
<add name="NORTHWINDEntities" providerName="System.Data.SqlClient" connectionString="data source=(local)/sqlexpress; initial catalog=NORTHWND;Integrated Security=SSPI" />
I've reviewed the post How to configure Fluent NHibernate with MySQL, but I'm relatively new to MySQL and I need to actually set up with connection string itself. I've installed MySQL as part of a WAMP install and need to fill in the actual connection string. Can someone help me by extending the linked answer to actually contain a full connection string example?
Appreciated.
Edit: I've tried several different things and I keep getting the following error message:
Can't load file FluentConfiguration.cs under d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg.
Check the file permission and the existence of that file.
I installed FNH via nuget, and I don't understand why it's looking at that path, as the d: drive is my CD and not a harddisk. Very confused.
The error you've pasted looks like Visual Studio trying to localise the sources to show you where the exception comes from. This is not the real exception message - you should have it somewhere there and it's probably something about wrong configuration.
If you've installed WAMP with default settings, it is configured to listen on 3306 port and have only local root account without password. So your connection string should look somehow like that:
Server=localhost; Port=3306; Database=[database_name_here]; Uid=root; Pwd=;
(Pwd= part may be not needed at all).
So you need to paste it in your App.config/Web.config's <connectionStrings> section:
<connectionStrings>
<add name="ConnectionString"
connectionString="Server=localhost; Port=3306;
Database=[database_name_here]; Uid=root; Pwd=;"
providerName="System.Data.SqlClient" />
</connectionStrings>
and then use the solution from linked question:
MySqlConfiguration.Standard.ConnectionString(
c => c.FromConnectionStringWithKey("ConnectionString")
)
Alternatively, you can paste the connection string directly in your Fluent's configuration, like this:
MySqlConfiguration.Standard
.ConnectionString.Is("Server=localhost; Port=3306;
Database=[database_name_here]; Uid=root; Pwd=;")
Anyway, this default root/no password configuration can be used only for local development and testing purposes.