In our company there is two team one .NET team and another is
PHP team, and me from .net team recently i got trained from angular course. My manager assigned a task using MYSQL database developed an angular application, why he told to use MYSQL database because existing applications used with MYSQL
datasbases, so my task is existing application MYSQL databases data to bring in angular application in the form of dashboard. So i started everything is going fine but one of my team member raised a question why you are using asp.net web api to connect mysql
databases and he told me that asp.net web api for window hosting.
So my overall question Is it is bad to use asp.net web api with existing application MYSQL databases.
In our company there is two team one .NET team and another is
PHP team, and me from .net team recently i got trained from angular course. My manager assigned a task using MYSQL database developed an angular application, why he told to use MYSQL database because existing applications used with MYSQL
datasbases, so my task is existing application MYSQL databases data to bring in angular application in the form of dashboard. So i started everything is going fine but one of my team member raised a question why you are using asp.net web api to connect mysql
databases and he told me that asp.net web api for window hosting.
So my overall question Is it is bad to use asp.net web api with existing application MYSQL databases.
Web API can be used with MySql.
However, your team member is correct, ASP.NET runs on a Windows machine. I recommend meeting with your team or manager to get clarification on what platform you are targeting.
You can connect to any kind of database from .NET and .NET Core. You can host .NET
Core Web APIs on Windows and Linux, but full framework apps (up to .NET 4.8) can only be hosted on Windows (unless you use Mono). However, you can't develop .NET Core applications with such an old
version of Visual Studio. You need at least Visual Studio 2017.
Your team member is not raising a valid point. asp.net can connect to any database. Mysql can be installed on a windows server. So the DBMS that you use should not matter. Your CTO asked you to use mysql because they probably do more of php. 95% of php applications
talk to Mysql. So if they want to build a micro service in .net dont be supprised if they telling you to use Mysql. it probably what they are use to.
In my own company I use .net core to Mysql. So it never a problem at all.
Continue your development. As long as your CTO agrees with the DB that you are using.
So your means i have to go with .net core api using visual studio 2017, if I want to host my api in Linux server.
Yes. VS 2017 or 2019.
There will be some minor implementation changes. For example, all .NET Core controllers derive from ControllerBase, and you decorate an API controller with [ApiController]. You might find some other differences too.
As an aside, that code is vulnerable to SQL injection attacks. When you rewrite your controllers, you should use parameterised queries like the Insert statement.
Member
236 Points
575 Posts
Is it is bad to use asp.net web api (using visual studio 2013) with MYSQL databases
Jul 25, 2020 10:27 AM|mazhar khan india|LINK
In our company there is two team one .NET team and another is PHP team, and me from .net team recently i got trained from angular course. My manager assigned a task using MYSQL database developed an angular application, why he told to use MYSQL database because existing applications used with MYSQL datasbases, so my task is existing application MYSQL databases data to bring in angular application in the form of dashboard. So i started everything is going fine but one of my team member raised a question why you are using asp.net web api to connect mysql databases and he told me that asp.net web api for window hosting.
So my overall question Is it is bad to use asp.net web api with existing application MYSQL databases.
All-Star
53041 Points
23612 Posts
Re: Is it is bad to use asp.net web api (using visual studio 2013) with MYSQL databases
Jul 25, 2020 12:41 PM|mgebhard|LINK
Web API can be used with MySql.
However, your team member is correct, ASP.NET runs on a Windows machine. I recommend meeting with your team or manager to get clarification on what platform you are targeting.
All-Star
194485 Points
28078 Posts
Moderator
Re: Is it is bad to use asp.net web api (using visual studio 2013) with MYSQL databases
Jul 26, 2020 05:18 AM|Mikesdotnetting|LINK
You can connect to any kind of database from .NET and .NET Core. You can host .NET Core Web APIs on Windows and Linux, but full framework apps (up to .NET 4.8) can only be hosted on Windows (unless you use Mono). However, you can't develop .NET Core applications with such an old version of Visual Studio. You need at least Visual Studio 2017.
Member
98 Points
326 Posts
Re: Is it is bad to use asp.net web api (using visual studio 2013) with MYSQL databases
Jul 26, 2020 09:03 AM|InspiredJide|LINK
Your team member is not raising a valid point. asp.net can connect to any database. Mysql can be installed on a windows server. So the DBMS that you use should not matter. Your CTO asked you to use mysql because they probably do more of php. 95% of php applications talk to Mysql. So if they want to build a micro service in .net dont be supprised if they telling you to use Mysql. it probably what they are use to.
In my own company I use .net core to Mysql. So it never a problem at all.
Continue your development. As long as your CTO agrees with the DB that you are using.
Member
236 Points
575 Posts
Re: Is it is bad to use asp.net web api (using visual studio 2013) with MYSQL databases
Jul 27, 2020 03:03 AM|mazhar khan india|LINK
Dear Mikesdotnett,
So your means i have to go with .net core api using visual studio 2017, if I want to host my api in Linux server.
Is there any difference's between asp.net web api(vs 2013) and .net core .api
In my asp.net web api(vs 2013) i call api like that.
below is my model class
namespace Dashboards.Models
{
public class Users
{
public int UserId { get; set; }
public string FullName { get; set; }
public string EmailId { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string Mobile { get; set; }
public int RoleId { get; set; }
public string Status { get; set; }
public string CreatedBy { get; set; }
public int StateId { get; set; }
public int CityId { get; set; }
}
}
Below is my controller class
namespace Dashboards.Controllers
{
public class UsersController : ApiController
{
public MySqlConnection con = WebApiConfig.conn();
public IHttpActionResult GetAllProduct()
{
IList<Users> pro = null;
try
{
con.Open();
MySqlCommand cmd = new MySqlCommand("select * from Users", con);
cmd.CommandType = CommandType.Text;
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
pro = ds.Tables[0].AsEnumerable().Select(dataRow => new Users { UserId = dataRow.Field<int>("UserId"), FullName = dataRow.Field<string>("FullName"), EmailId = dataRow.Field<string>("EmailId"), UserName = dataRow.Field<string>("UserName"), Password = dataRow.Field<string>("Password"), Mobile = dataRow.Field<string>("Mobile"), RoleId = dataRow.Field<int>("RoleId") }).ToList();
}
finally
{
con.Close();
}
if (pro.Count == 0)
{
return NotFound();
}
return Ok(pro);
}
// public IHttpActionResult PostNewUsers(Users)
public IHttpActionResult PostNewClient(Users cli)
{
string FullName = cli.FullName;
string EmailId = cli.EmailId;
string UserName = cli.UserName;
string Password = cli.Password;
string Mobile = cli.Mobile;
int RoleId = cli.RoleId;
string CreatedBy = cli.CreatedBy;
int StateId = cli.StateId;
int CityId = cli.CityId;
string sqlStatement = "INSERT INTO Users (FullName,EmailId,UserName,Password,Mobile,RoleId,CreatedBy,StateId,CityId) VALUES (@FullName,@EmailId,@UserName,@Password,@Mobile,@RoleId,@CreatedBy,@StateId,@CityId)";
MySqlCommand comm = new MySqlCommand(sqlStatement, con);
comm.CommandType = CommandType.Text;
comm.Parameters.AddWithValue("@FullName", FullName);
comm.Parameters.AddWithValue("@EmailId", EmailId);
comm.Parameters.AddWithValue("@UserName", UserName);
comm.Parameters.AddWithValue("@Password", Password);
comm.Parameters.AddWithValue("@Mobile", Mobile);
comm.Parameters.AddWithValue("@RoleId", RoleId);
comm.Parameters.AddWithValue("@CreatedBy", CreatedBy);
comm.Parameters.AddWithValue("@StateId", StateId);
comm.Parameters.AddWithValue("@CityId", CityId);
try
{
con.Open();
comm.ExecuteNonQuery();
}
catch (MySqlException e)
{
// do something with the exception
// do not hide it
// e.Message.ToString()
}
return Ok();
}
public IHttpActionResult PutOldUsers(Users u)
{
string sql = "update Users set FullName='" + u.FullName + "',EmailId=" + u.EmailId + "',UserName=" + u.UserName + "',Password=" + u.Password + "',Mobile=" + u.Mobile + "',RoleId=" + u.RoleId + "',CreatedBy=" + u.CreatedBy + " where UserId=" + u.UserId + "";
try
{
con.Open();
MySqlCommand cmd = new MySqlCommand(sql, con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
return Ok();
}
public IHttpActionResult Delete(int id)
{
string sql = "delete from users where UserId=" + id + "";
try
{
con.Open();
MySqlCommand cmd = new MySqlCommand(sql, con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
return Ok();
}
}
}
All-Star
194485 Points
28078 Posts
Moderator
Re: Is it is bad to use asp.net web api (using visual studio 2013) with MYSQL databases
Jul 27, 2020 09:28 AM|Mikesdotnetting|LINK
There will be some minor implementation changes. For example, all .NET Core controllers derive from ControllerBase, and you decorate an API controller with [ApiController]. You might find some other differences too.
As an aside, that code is vulnerable to SQL injection attacks. When you rewrite your controllers, you should use parameterised queries like the Insert statement.