v-wywang
11/28/2007 12:07:00 PM
Hello Gerry,
Thanks for your reply.
First of all, I'd like to summary what I understood.
a) I understood you received an "Invalid Character" exception when the
connection for DataContext includes "|DataDirectory|". Please don't
hesitate to correct me if I misunderstood anything here.
If this is the case, do you have any simple code to reproduce this issue? I
have tried it on my side. But, it seems works fine. I follow the steps as
below:
1) Add linqtosql into my project.
2) Add a new connection (attached file) in Server Explorer.
3) Drag-drop a table into linqtosql designer interface.
4) The connection of datacontext is
[Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\testDB.mdf;Integrated
Security=True;User Instance=True]
5) At last, I add the following code in my application.
private void button1_Click(object sender, EventArgs e)
{
ClassLibrary1.DataClasses1DataContext dccdc = new
ClassLibrary1.DataClasses1DataContext();
bool f = dccdc.DatabaseExists();
}
It works file. The value retried by DataExists method is true. I didn't get
any error message. If I'm missing anything here, please correct me.
b) I understood the issue is that change the
DataConext.connection.connectionstring anywhere but in constructor doesn't
take effect, correct? Please correct me if I misunderstood anything here.
I made change on DataContext.connecton in my application, and check that
property again. It really takes effect. Did I miss anything here? please
correct me.
ClassLibrary1.DataClasses1DataContext dccdc = new
ClassLibrary1.DataClasses1DataContext();
dccdc.Connection.ConnectionString = @"Data Source=.\sqlexpress;Initial
Catalog=test;Integrated Security=True";
System.Windows.Forms.MessageBox.Show(dccdc.Connection.ConnectionString);
c) It seems what your main concern is that CreatDatabase() method throws
"already exists" exception even though DatabaseExists return false (and the
db file doesn't exists). If I misunderstood anything here, please correct
me. I'm not a SQL guy, but I'm sorry to say I don't think SQL Express makes
a permanent association between the database filename and location. Do you
have any reproduce steps for us? It will help on research very much. Thanks.
Please feel free to update here again, if you have any more concern. We are
glad to assist you.
Have a great day,
Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.