how to solve 'Keyword not supported: 'metadata' - c#

I'm trying to connect to my database with SQL client but I can't connect.
Here is my connection string:
<add name="RegisterDBEntities"
connectionString="metadata=res://*/Register.csdl|res://*/Register.ssdl|res://*/Register.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\RegisterDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />

Related

Publishing asp.net mvc application Connection String

I am using Entity Framework in my Application.
I am publishing application for first time to somee.com
But I have the problem with the connection string.
My connection string in web.config
<connectionStrings>
<add name="StoreDBContext" connectionString="metadata=res://*/Models.StoreModel.csdl|res://*/Models.StoreModel.ssdl|res://*/Models.StoreModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\StoreDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="StoreDB" connectionString="metadata=res://*/Models.StoreModel.csdl|res://*/Models.StoreModel.ssdl|res://*/Models.StoreModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\StoreDB.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
and by database connection string on somee database is :
workstation id=storebd.mssql.somee.com;packet size=4096;user id=****;pwd=****;data source=storebd.mssql.somee.com;persist security info=False;initial catalog=storebd
How should I format connection string in web.config file according to database connection provided by some.

System.Data.ProviderIncompatibleException in Entity Framework

Is there any thing missing in my connection string so that i am getting this error:
An exception of type 'System.Data.ProviderIncompatibleException' occurred in EntityFramework.dll but was not handled in user code Additional information: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.
This is my connection String in web.config:
<connectionStrings>
<add name="OnlineStoreEntities" connectionString="Data Source=SERVERNAME\SQLEXPRESS;Initial Catalog=MVCOnlineShop;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MVCOnlineShop" connectionString="metadata=res://*/Models.ShopModel.csdl|res://*/Models.ShopModel.ssdl|res://*/Models.ShopModel.msl;provider=System.Data.SqlClient;provider connection string="data source=AHMADZAKARIA-PC;initial catalog=MVCOnlineShop;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Check your connection string in *.config file and most probably you are missing the providerName="System.Data.SqlClient". See Entity Framework Config File Settings for more information

App.Config transformation not working

I am trying to change the app.config dinamically on my build server, I created a Configuration called Build, and I have these 4 .config files.
this is my app.config
<connectionStrings>
<!--configSource="connectionStrings.config"-->
<add name="TestContext" connectionString="Data Source=ServerDoesNotExist;Initial Catalog=TestDb; Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>
and on my app.build.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionstrings xdt:transform="Replace">
<add name="TestContext" connectionstring="Data Source=REALEXISTINGSERVER;Initial Catalog=TestDb; Integrated Security=true" providername="System.Data.SqlClient"/>
</connectionstrings>
</configuration>
However when I created the build definition and added the configuration =Build I get this error
Error: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception: The network path was not found
Which means is taking the app.config file and not the transformation
You can use SetAttributes
<connectionStrings>
<add name="TestContext" connectionString="Data Source=REALEXISTINGSERVER;Initial Catalog=TestDb; Integrated Security=true" providername="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
please refer to
How do I use Web.Config transform on my connection strings?

Cannot connect to local DB at another PC. ASP .NET MVC4

I have created an mvc 4 database application on "PC1". I just have chosen by right click "Database SQL Server" and created Entity Framework with Database First approach. It works okay at "PC1". But when I copied my project to another PC, then the project failed.
I do not have an SQL Server at the PC. I just copied the mvc 4 project with local database.
The error is: "...(provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
I suppose that I should rewrite connection string. I've done this steps:
http://msdn.microsoft.com/en-us/library/hh873188.aspx
And I have tried to change a connection string from:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-TestApplication-20140918110411;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
To:
I have added name of PC(TomPC) to connection string:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.TomPC\SQLEXPRESS;Initial Catalog=aspnet-TestApplication-20140918110411;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.TomPC\SQLEXPRESS;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.TomPC\SQLEXPRESS;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
However, it fails with the same error.
I would greatly appreciate any help!
You will also need to ensure that TCP/IP is enabled in SQL Server config on TomPC, and also open up port 1433 (the default port, but it might be different, e.g. if there's more than one instance of SQL running on that PC).
Data Source=.\SQLEXPRESS
The . means "localhost" or 127.0.0.1
So adding the . means localhost\SQLEXPRESS or 127.0.0.1\SQLEXPRESS
You need to change it to:
Data Source=TomPC\SQLEXPRESS
I've found an answer. The application could not connect as connection string should be modified as LocalDB:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=aspnet-TestApplication-20140918110411;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
http://www.asp.net/mvc/tutorials/mvc-5/introduction/creating-a-connection-string

How to configure connection string to RDS Instance (MSSQLServer Express)

I have connected from my PC to my instance RDS (MSSQL Server Express) using Managment Studio without problems, because I have already configured the policy groups and other stuff.
My "simple" problem is when I try to connect from my WebApp, I have a web.config and this is my configuration in ASP.NET MVC 5 Project... very easy:
Can you help to configure my connection string correctly?
Thanks!!
<add name="Entities" connectionString="metadata=res://*/Business.Interactive.Model.csdl|res://*/Business.Interactive.Model.ssdl|res://*/Business.Interactive.Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=aa1XXXXXXXXXbi.cruXXXXXXym4.eu-west-1.rds.amazonaws.com:1433;Database=Business.interactive.gci;User Id=userroot;
Password=XXXXXXXX;pooling=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="myBusinessContext" connectionString="Data Source=aa1XXXXXXXXXbi.cruXXXXXXym4.eu-west-1.rds.amazonaws.com:1433;Database=Business.interactive.gci;User Id=userroot;
Password=XXXXXXXX;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
Ok, The problem was the length of the name of the database and I also I had to delete the number port:
Finally:
<add name="Entities" connectionString="metadata=res://*/Business.Interactive.Model.csdl|res://*/Business.Interactive.Model.ssdl|res://*/Business.Interactive.Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=aa1XXXXXXXXXbi.cruXXXXXXym4.eu-west-1.rds.amazonaws.com;Database=Businessgci;User Id=userroot;
Password=XXXXXXXX;pooling=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="myBusinessContext" connectionString="Data Source=aa1XXXXXXXXXbi.cruXXXXXXym4.eu-west-1.rds.amazonaws.com;Database=Businessgci;User Id=userroot;
Password=XXXXXXXX;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
Regards!!

Categories