mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-04-24 23:36:51 -05:00
Made connection string configurable.
This commit is contained in:
parent
906249a212
commit
3f0d747b81
|
|
@ -10,6 +10,9 @@
|
|||
<add name="ApplicationServices"
|
||||
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
|
||||
providerName="System.Data.SqlClient" />
|
||||
<add name="pkmnFoundationsConnectionString"
|
||||
connectionString="Server=10.211.55.2;Database=gts;User ID=gts;Password=gts;Pooling=true;"
|
||||
providerName="MySql.Data.MySqlClient" />
|
||||
</connectionStrings>
|
||||
|
||||
<system.web>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Data;
|
||||
using PkmnFoundations.Structures;
|
||||
using System.Configuration;
|
||||
|
||||
namespace PkmnFoundations.Data
|
||||
{
|
||||
|
|
@ -18,11 +19,27 @@ namespace PkmnFoundations.Data
|
|||
{
|
||||
if (m_instance == null)
|
||||
{
|
||||
m_instance = new DataMysql();
|
||||
m_instance = CreateInstance();
|
||||
}
|
||||
return m_instance;
|
||||
}
|
||||
}
|
||||
|
||||
private static DataAbstract CreateInstance()
|
||||
{
|
||||
ConnectionStringSettings connStr = ConfigurationManager.ConnectionStrings["pkmnFoundationsConnectionString"];
|
||||
if (connStr != null)
|
||||
{
|
||||
switch (connStr.ProviderName)
|
||||
{
|
||||
case "MySql.Data.MySqlClient":
|
||||
return new DataMysql(connStr.ConnectionString);
|
||||
default:
|
||||
throw new NotSupportedException("Database provider not supported.");
|
||||
}
|
||||
}
|
||||
else throw new NotSupportedException("No database connection string provided. Please add one in web.config or app.config.");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Utility
|
||||
|
|
|
|||
|
|
@ -12,10 +12,16 @@ namespace PkmnFoundations.Data
|
|||
public class DataMysql : DataAbstract
|
||||
{
|
||||
#region Initialization
|
||||
public DataMysql(String connString)
|
||||
{
|
||||
ConnectionString = connString;
|
||||
}
|
||||
|
||||
public String ConnectionString { get; set; }
|
||||
|
||||
private MySqlConnection CreateConnection()
|
||||
{
|
||||
// hard-coded for now, will need to add configuration later
|
||||
return new MySqlConnection("Server=10.211.55.2;Database=gts;User ID=gts;Password=gts;Pooling=true;");
|
||||
return new MySqlConnection(ConnectionString);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
<HintPath>lib\mysql.data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite">
|
||||
<HintPath>lib\System.Data.SQLite.dll</HintPath>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user