Warm tip: This article is reproduced from serverfault.com, please click

Using port in sql connection string in C# Entity Framework: Keyword not supported: 'port'

发布于 2020-11-28 04:09:43

I've been working to set up Entity Framework using VS code, using this tutorial:
https://www.learnentityframeworkcore.com/walkthroughs/aspnetcore-application
however, when executing the migration- I encountered this specific error: Keyword not supported: 'port'
The best reference I've found thus far to help out is this stackoverflow, however, due to the setup I've been following thus far, none of the solutions seem to work
C# Entity Framework: Keyword not supported: 'port'

This is the code that seems to be causing me trouble:

using Microsoft.EntityFrameworkCore;
namespace EFPrac
{
    
    public class EFCoreWebDemoContext : DbContext
    {
        public DbSet<Book> Books { get; set; }
        public DbSet<Author> Authors { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {            
            string connectionString = "server=localhost;port=3306;database=EFpractice;uid=root,Pwd=****";
            optionsBuilder.UseSqlServer(connectionString);
        }
    }
}

I've been stuck on this for a while, so any help would be greatly appreciated.
Questioner
GCK
Viewed
0
hesam akbari 2020-11-28 12:31:04

connectionstrings.com is a great site for connection string question

Using a non-standard port

If your SQL Server listens on a non-default port you can specify that using the servername,xxxx syntax (note the comma, it's not a colon).

Server=myServerName,myPortNumber;Database=myDataBase;User Id=myUsername;Password=myPassword;

Also, try this way:

string connectionString="server=localhost,3306;database=EFpractice;uid=root,Pwd=****"