I'm new to C# and asp.net programming and currently use MsSQL DataBases linked to my project with a DBML, using Linq to SQL, with my connection string in my web.config and all my database functions are stored in class managers. Examples below.
Connection string in web.config:
<add name="ConnectionString" connectionString="Data Source=server;Initial Catalog=database;Persist Security Info=True;User ID=UserId;Password=password" providerName="System.Data.SqlClient" />
Example Class Manager:
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Web;
public class DataManager
{
private DataContext dc;
public DataManager()
{
dc = new DataContext();
}
public News GetNews(int newsId)
{
return dc.News.Where(x => x.NewsId == newsId).Where(x => x.Deleted == false).FirstOrDefault();
}
public News News_Save(News n)
{
if (n.NewsId == 0)
dc.News.InsertOnSubmit(n);
dc.SubmitChanges();
return n;
}
}
What I would like to know is how I can have a similar setup to this but to access a MySQL database. All the examples I have seen require creating a connection string within the page each time you want to use a function which seems wasteful and unnecessary to me. Is there anyway I can use my current structure but access a MySQL database with or without a DBML?