Keyword not supported: 'metadata' - asp.net-mvc-3

I am trying to publish my mvc 3 project but i can`t connect to the sql server(using EF), because of the wrong connection string. Here it is:
<add name="PackStoreEntities" connectionString="metadata=res://*/Models.PackStore.csdl|res://*/Models.PackStore.ssdl|res://*/Models.PackStore.msl;provider=System.Data.SqlClient;provider connection string="workstation id=PackStore.mssql.somee.com;packet size=4096;user id=*****;pwd=****;data source=PackStore.mssql.somee.com;persist security info=False;initial catalog=PackStore"" providerName="System.Data.EntityClient" />
I took this part form the my hoster:
workstation id=PackStore.mssql.somee.com;packet size=4096;user id=*****;pwd=****;data source=PackStore.mssql.somee.com;persist security info=False;initial catalog=PackStore
Mvc project works well on the local server, but when publishing i get "Keyword not supported: 'metadata' " . Where is my mistake? Thnaks for the answers.

try this one...
<add name="PackStoreEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string='Data Source=PackStore.mssql.somee.com;Initial Catalog=PackStore;User ID=***;Password=****;'" providerName="System.Data.EntityClient" />
Edit..
<add name="PackStoreEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string='workstation id=PackStore.mssql.somee.com;packet size=4096;user id=*****;pwd=****;data source=PackStore.mssql.somee.com;persist security info=False;initial catalog=PackStore;'" providerName="System.Data.EntityClient" />

I got this error while converting from Linq To Sql to Entity framework as well, even after fixing my connection strings. It turned out some asp:SqlDataSource controls needed to be switched to asp:EntityDataSource.
Before:
<asp:SqlDataSource ID="SqlDataSourceProducts" runat="server" SelectCommand="SELECT Id, Description FROM [Product]"
ConnectionString="<%$ ConnectionStrings:crmConnectionString %>" CacheDuration="5" CacheExpirationPolicy="Absolute">
</asp:SqlDataSource>
After:
<asp:EntityDataSource ID="SqlDataSourceProducts" runat="server" Select="Id, Description"
EntitySetName="Products" ConnectionString="<%$ ConnectionStrings:crmConnectionString %>" DefaultContainerName="CRM" >
</asp:EntityDataSource>

In your web.config you need to have two separate connections: One is for the Entity Frame work and one is for ADO.net
Should look like this:
<connectionStrings>
<add name="LoginDB" connectionString="Data Source=****;Initial Catalog=int422_113b16;User ID=****;Password=****" />
<add name="BlogEntities" connectionString="metadata=res://*/App_Code.BlogModel.csdl|res://*/App_Code.BlogModel.ssdl|res://*/App_Code.BlogModel.msl;provider=System.Data.SqlClient;provider connection string="data source****;initial catalog=int422_113b16;user id=****;password=****;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>

Remove he meta data from your connection string. That is only for the local debugging. For the online application can does not require that.
Kindly try the connection string given by naim

Had a similar problem, seems like the connection string from the somee server has to be between two "
That's all I changed and it works...

I'm not sure why people think that you need two connections in your web.config, that's not true. First thing I like to check is to see if my connection works in Visual Studio. Try going to your server explorer and connect to your database there. If you are able to connect with no problem and you are able to see your tables then you know its not a connection problem. Second thing make sure that your Model name matches the name in your web.config. This minimizes the amount of confusion in your project and finally make sure that your model name space points to your projects namespace, this way you can just call on your model by its name and not have to import or fully qualify it.
You should be able to create a strong view using any of the tables in your model. That's what I did for mine, I didn't modify the connection string like many suggest, or removed the metadata.
Check this troubleshooting guide it might shine some light, and help you understand how the entity connection works.

I had the same exception, but was able to fix it by keeping the ConnectionString the same but using an EntityConnection instead of a SqlConnection.

Related

How to allow a DELETE method with IIS Express and Web API?

I am trying to send a delete request to my Web API service via Fiddler and am getting back a 405 "Method not allowed" error.
I have read extensively about removing the "WebDAV" module in web.config and similar suggestions (WebDAV is not enabled in my applicationhost.config anyway), but nothing I have tried has worked.
My service is currently running on IIS Express 10 (launching from Visual Studio). I do have this in my web.config file:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"/>
I would have thought the verb="*" piece would have allowed DELETE, but it does not seem to work.
One other note - when I inspect the response in Fiddler, under the Security heading it says: Allow: GET, POST.
I am not sure where that "Allow" parameter is being set (I am new to Web API).
Any help would be greatly appreciated. Please let me know what other information you need from me and I will add it.
Thank you!
Just reproduced this by creating a new webapi project [targeting .net framework 4.7.1]
Through Fiddler, I can hit the DELETE endpoint without any changes to web.config.
Please make sure to use correct endpoint including the id parameter.
e.g http:localhost:xxxx/api/values/id // please include the id and xxxx is port number.
If http:localhost:xxxx/api/values is used without id , I get the same result 405 Method Not Allowed
Hope this helps.
You can modify the IIS Express applicationHost.config in the %userprofile%\documents\IISExpress\config folder.  To enable PUT and DELETE for extensionless Urls scroll down to the bottom of the IIS Express applicationHost.config file and look for a handler entry that starts with: <add name="ExtensionlessUrl-Integrated-4.0".... In the "verb" attribute add PUT and DELETE so the "verb" attribute looks like:  verb="GET,HEAD,POST,DEBUG,PUT,DELETE"
Update your web config like this
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/> <!-- ADD THIS -->
</modules>

How to verify that WebMatrix is performing web.config transformations?

I have an MVC5 project that I'm publishing to Azure via WebMatrix, where I've defined a connection string for the database server in production in the web.config like this:
<configuration>
<connectionStrings>
<add
name="MyProjectContainer"
providerName="System.Data.EntityClient"
connectionString="[metadata stuff];
provider=System.Data.SqlClient;
provider connection string="
data source=x1.database.windows.net,1433;
initial catalog=MyProject;
Uid=x#x1;
app=EntityFramework;
Pwd=xxx
""
/>
</connectionStrings>
...for local development I have an entry in the web.Debug.config like this:
<connectionStrings>
<add xdt:Transform="Replace" xdt:Locator="Match(name)"
name="MyProjectContainer"
providerName="System.Data.EntityClient"
connectionString="[metadata stuff];
provider=System.Data.SqlClient;
provider connection string="
data source=MyDevServer;
initial catalog=MyProject;
integrated security=True;
multipleactiveresultsets=True;
App=EntityFramework
""
/>
I chose this approach because having an empty connectionString in the web.config with a transform in web.Release.config didn't seem to work. when I publish my app works on Azure, however, when I try to run it locally, Visual Studio is trying to connect to the Azure database instead of the local server.
So I have 2 questions:
What could I be missing that transforms aren't working when I publish in WebMatrix? because if I could make that work I would have the connectionString in the main web.config as empty and the right values in web.Debug.config and web.Release.config
What is wrong with Visual Studio that it doesn't know how to do the transforms either?
has anyone out there struggled with this?

"The provider did not return a ProviderManifestToken string"

I'm trying to teach myself .Net MVC 3, and am following this tutorial: http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3 and have reached the step where you create the controller for the Model you created earlier (http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/accessing-your-model's-data-from-a-controller).
When I try to create the controller, I get the "The provider did not return a ProviderManifestToken string" error. A bit of googling leads me to believe this is due to an error with my connection string.
The thing is I'm not running SQL Server locally, so I can't copy the example connectionString. Here's what I've got now:
connectionString="Data Source=1.2.3.4\MSSQLSERVER;Initial Catalog=myDBname;Integrated Security=False;User ID=myUsername;Password=myPassword"
I've tried using SSMS to log on to the database using the username and password, and it works, so the problem is not with the user itself.
Any ideas?
If you are using SQL Azure, this error can be caused if the Azure Database Firewall is not set up to allow your IP Address. Make sure check to make sure you are authorizing the IP Address. This error doesn't necessarily point you in that direction.
I had same problem and solved it by following method.
Just Check the db instance's Object name, it might be like:
private Model_ db = new Model_();
If so, then replace it with MovieDBContext like:
private MovieDBContext db = new MovieDBContext();
(or what you set the Class name in Model/Movies.cs like
public class MovieDBContext : DbContext
{
public DbSet < Movie> Movies { get; set; }
)
I had the same problem until I came across this answer
DB Connection string in Web.config to use attached .mdf database won't work
"If you have the *.mdf placed in App_Data folder, using this format works:"
<connectionStrings>
<add name="ConnectionName"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|DatabaseName.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I also used the tutorial, but I had database file *.mdf otherwise than in the tutorial *.sdf.
Maybe this solution will be helpful.
I figured it out: turns out that "\MSSQLSERVER" isn't needed in my case. I'm not sure if it's because I'm connecting by IP or if it's specific to my server setup, but removing it solved the problem.
I found my answer here:
"There are two web.config files in ASP.NET MVC3 applications. One is
in the root where connection strings should be placed and the other is
under Views folder, where connections should not be placed. Guess
where I had my connection!"

'Username cannot be found' after modifying provider element

I am having trouble hitting the ASPNETDB.MDF database. It actually works fine until I add some code to the web config. This is the code I added that prevents me from connecting...
<membership defaultProvider="CustomizedProvider">
<providers>
<add name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="LocalSqlServer"
applicationName="MyApp"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
/>
</providers>
</membership>
I added it because I wanted to take advantage of the password constraints it affords. That said, the name of the connection string hasn't changed and no code change. But when I try to log in its telling me that the username cannot be found. I should ntoe that I am using the same un and pw which, by the way, meet these new constraints.
This is an ASP.NET 4.0 application
There doesn't seem to be anything wrong with the syntax, if the connection string name is correct then are you sure the application name is correct? This should be the application name in the database (defaults to '/') not the name of your application in visual studio.

Asp.net Membership - Accounts getting locked out

We're using the standard ASP.net membership features that come with asp.net.
Certain accounts in our membership database have a "Locked Out" flag set to true - when/how does this happen?
After a configurable number of failed logins (maxInvalidPasswordAttempts, default = 5) within a configurable length of time (passwordAttemptWindow, default = 10 minutes), the account will be locked out.
see here for membership related configuration properties
These 4 guys did a great job of explaining in depth the asp.net membership controls
<system.web>
... authentication & authorization settings ...
<membership defaultProvider="CustomizedProvider">
<providers>
<add name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MyDB"
applicationName="MyProject"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0" />
</providers>
</membership>
basically add your provider and then set the setting the way you'd like them
When someone try to login 5 times (or whatever "maxInvalidPasswordAttempts" is set to) with the wrong password the account gets locked out ...
to avoid this in the future change the attribute maxInvalidPasswordAttempts in the web.config
example :
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="SqlProvider"
....
maxInvalidPasswordAttempts="the new value here "
/>
</providers>
Account locking is a feature of SqlMembershipProvider that provides a safeguard against password guessing.
Looking at this page you can see that the aspnet_Membership table has IsLockedOut, LastLockoutDate, FailedPasswordAttemptCount, FailedPasswordAnswer-AttemptCount. By reviewing this table and those columns you should be able to determin who is having a failed login, when they failed on their login, and how many times they failed.
The actual count for the number of login tries can be sest in the section of the web.config. You can read more about account locking here.

Resources