Connection String Incorrectly Formatted [migrated]
- by Randy E
I'm running into some issues. Every time I launch into debug mode and hit the "Create User" button, I'm getting an exception being thrown that is due to the Connection String either being in the wrong syntax or just wrong.
Using Visual Studio 2010, project is .NET 3.5 with SQL 2008 Express.
This is just a personal project that I'm testing some other things with, I know this generally isn't the recommended format but for a personal small project, I don't see the point in doing it any other way. The things I'm testing actually work :)
Data Source=.\SQLEXPRESS;AttachDbFilename=|Data Directory|ASPAppDatabase.mdf;Integrated Security=True;User Instance=True
That doesn't work.
Data Source=.\SQLEXPRESS;AttachDbFilename="|Data Directory|ASPAppDatabase.mdf";Integrated Security=True;User Instance=True
Neither does that.
Data Source=.\SQLEXPRESS;AttachDbFilename='|Data Directory|ASPAppDatabase.mdf';Integrated Security=True;User Instance=True
And again, neither does that :/
However, rather than using "|Data directory| if I use the full path to the local DB file it works just fine and no exception is thrown, and I can read and write as I need.
And just to cover all my bases, here is the button click event that creates the User.
protected void btnAddUser_Click(object sender, EventArgs e)
{
Membership.CreateUser(txtUserName.Text, txtPassword.Text);
btnLogin_Click(sender, e);
}
So, what am I missing in regards to the |Data Directory|?
Here is an example of the above not working correctly..taken directly from web.config.
<add name="ASPAppDatabaseConnection" connectionString='Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPAppDatabase.mdf;Integrated Security=True;User Instance=True'/>