ASP.Net MVC 6 Deployment
Does anyone know how to deploy and ASP.Net MVC in Railway with a MySQL database?
24 Replies
Please provide your project ID or reply with
N/A
. Thread will automatically be closed if no reply is received within 10 minutes. You can copy your project's id by pressing Ctrl/Cmd + K -> Copy Project ID.You might find these helpful:
- MySQL | Railway Docs
- PostgreSQL | Railway Docs
- MongoDB | Railway Docs
⚠️ experimental feature
You should be able to add a MySQL database service and then deploy your code as usual.
(Railway has built-in .NET support through Nixpacks, so you shouldn't need a Dockerfile or anything: https://nixpacks.com/docs/providers/csharp)
Cool will check it out
No project ID was provided. Closing thread.
I was able to able to deploy it but it fails to connect to my MySQL. I also noticed that it did not automatically generated a table when I added my Github repo
N/A
N/AS
N/A
Are you using the DATABASE_URL env var to connect?
Not really sure where to put that in my project
Are you using EF6?
the env var DATABASE_URL should be passed as the connection string
Something like
do you mean entity framework?
Yes
yup it saya 6.0.10
says*
Where are you initializing your DB connection?
no sure about that because I always use code gen in Visual Studio do you want to take a look at my github repo? its just a todo app for practice
Sure
GitHub
GitHub - nadjitan/TodoWebApp: Simple todo web app usin asp.net mvc
Simple todo web app usin asp.net mvc. Contribute to nadjitan/TodoWebApp development by creating an account on GitHub.
1. You're trying to use SQL Server right now
oh
What do I need to change?
First, add the
MySql.Data.EntityFramework
package
Then replace UseSqlServer
with UseMySql
And replace the GetConnectionString
call with System.Environment.GetEnvironmentVariable("DATABASE_URL")
And see if that works
(I'm afraid I haven't worked with .NET that much)
All in Program.cs
Any help is appreciated and will now try your suggestions
I noticed that in Railway they have a different version of MySQL. How do I turn this into their format?
I tried doing this steps but nothing worked so I ended up with this code instead even though it still does not work.
Program.cs
I also needed to change my TodoWebApp.csproj
file into this:
This is the error I get in my body when my app is deployed in Railway. I think that
Environment.GetEnvironmentVariable("DATABASE_URL")
is what keeps me from accessing my env variable even though I already created DATABASE_URL
in my Variables.1. Please use
UseMySql
instead of UseSqlServer
2. Here's an updated query; the one you sent isn't MySQL, it's SQL Server:
3. GetEnvironmentVariable
isn't the problem.
4. Remove Microsoft.EntityFrameworkCore.SqlServer
and replace it with MySql.Data.EntityFramework
(in the csproj)
5. Set DOTNET_ENVIRONMENT=Production
on Railway.Ok I will try again
Oh up until now I thought it was my version that is different
Everything works now 😅. Thanks again for pointing out to get the env variables of Railway!
Program.cs
TodoWebApp.csproj
I used Pomelo.EntityFrameworkCore.MySql
since MySql.Data.EntityFramework
is deprecated.Great! No problem!