Hi. I'm using LINQ to SQL.
I wanna create a database with LINQ but the following exception has occurred : Illegal characters in path.
My snippet code :
PHP Code:
public static string DBFolder = Application.StartupPath + "\\SQL\\";
//the path is equal with "D:\My Works\C#\Win Form\Reza Restaurant\RezaRestaurant\bin\Release\SQL"
private void MainForm_Load(object sender, EventArgs e)
{
if (!Directory.Exists(StaticVariables.DBFolder))
Directory.CreateDirectory(StaticVariables.DBFolder);
using (RezaRestaurant.SQL.DataClasses1DataContext dbc = new RezaRestaurant.SQL.DataClasses1DataContext())
{
if (!File.Exists(StaticVariables.DBFolder + dbc.Mapping.DatabaseName + ".mdf") && !dbc.DatabaseExists())
{
RezaRestaurant.SQL.DataClasses1DataContext db = new RezaRestaurant.SQL.DataClasses1DataContext(StaticVariables.DBFolder + dbc.Mapping.DatabaseName + ".mdf", dbc.Mapping.MappingSource);
db.CreateDatabase();//Exception
}
}
}
Stack Trace :
PHP Code:
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.NormalizePathFast(String path, Boolean fullCheck)
at System.IO.Path.NormalizePath(String path, Boolean fullCheck)
at System.IO.Path.GetFullPathInternal(String path)
at System.IO.Path.GetFullPath(String path)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.CreateDatabase()
at System.Data.Linq.DataContext.CreateDatabase()
at RezaRestaurant.MainForm.MainForm_Load(Object sender, EventArgs e) in D:\My Works\C#\Win Form\Reza Restaurant\RezaRestaurant\Forms\MainForm.cs:line 364
Could you please guide me ? Thanks.