“The provider did not return a ProviderManifestTok

2019-07-25 14:51发布

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?

5条回答
疯言疯语
2楼-- · 2019-07-25 15:14

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.

查看更多
孤傲高冷的网名
3楼-- · 2019-07-25 15:15

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; }
)
查看更多
冷血范
4楼-- · 2019-07-25 15:18

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.

查看更多
趁早两清
5楼-- · 2019-07-25 15:18

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!"

查看更多
做自己的国王
6楼-- · 2019-07-25 15:36

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.

查看更多
登录 后发表回答