Connection string between IIS and SQL server

后端 未结 4 725
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 14:44

I\'m confused by the connection string in the Web.config file of project with Entity Framework Web API. There are a lot of variants I tried, but none of them was helping me out.

相关标签:
4条回答
  • 2021-01-21 15:01

    This tutorial how to setup SQL Server 2008 for an ASP.net website on IIS 7.0 brought me close to the solution.

    Basically, what you need to do is

    1. Install SQL server.
    2. Allow TCP/IP connections to the SQL server.
    3. Attach your database.
    4. Create a login. I'm using SQL Authentication.
    5. Assign the user permissions to your database.
    6. Configure your database connection string.

    Changing the name of my connection string helped me establish the connection finally.

    <connectionStrings>
           <add name="MyProjectContext" connectionString="Server=.\SQLEXPRESS;Database=MyProject;User Id=John;Password=duck;" providerName="System.Data.SqlClient" />
    </connectionStrings>
    

    The context model required this name.

    public class MyProjectContext : DbContext
    {
    
        public MyProjectContext() : base("name=MyProjectContext")
        {
        }
    
        public DbSet<Model1> Model1 { get; set; }
        public DbSet<Model2> Model2 { get; set; }
    }
    
    0 讨论(0)
  • 2021-01-21 15:02
    <connectionStrings>
        <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyProject;User ID=John;Password=duck" providerName="System.Data.SqlClient" />
    </connectionStrings>
    

    Please try the above connection syntax.

    0 讨论(0)
  • 2021-01-21 15:13

    Use the Event Viewer to get more information on what the 500 error actually is.

    0 讨论(0)
  • 2021-01-21 15:13

    Basically just amend your connection string using Integrated Security=False like :

    and it will work ...

    0 讨论(0)
提交回复
热议问题