Andrew
Andrew

Reputation: 23

Format of the initialization string does not conform to specification starting at index 50

I have no idea what it means, can I get some help please

"Format of the initialization string does not conform to specification starting at index 50."

Code:

InitializeComponent();
connString = "Data   Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\andrew\\Documents\\Vinyl0.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
query = "SELECT * FROM Record";
dAdapter = new SqlDataAdapter(query, connString); //This is where the error appears.
dTable = new DataTable();
cBuilder = new SqlCommandBuilder(dAdapter);
cBuilder.QuotePrefix = "[";
cBuilder.QuoteSuffix = "]";
myDataView = dTable.DefaultView;
dAdapter.Fill(dTable);
BindingSource bndSource = new BindingSource();
bndSource.DataSource = dTable;

Upvotes: 1

Views: 3391

Answers (4)

Theodoros Chatzigiannakis
Theodoros Chatzigiannakis

Reputation: 29213

I'm noticing a C:\\Users\andrew\\.

It looks like you were going for a \\ in the middle but ended up with \a instead, which is an escape sequence for a character that ruins the format of your connection string.

Upvotes: 9

TYY
TYY

Reputation: 2716

C:\\Users\ is your problem, you need to change it to C:\\Users\\

Upvotes: 2

Jon Skeet
Jon Skeet

Reputation: 1499760

I suspect this is the problem:

C:\\Users\andrew

\a is the escape sequence for the "alert" character (U+0007)... I suspect you wanted a backslash followed by "a". You were unlucky that you didn't just get a compile-time error, which you'd have done if you'd had \j or some other invalid escape sequence.

I would suggest using a verbatim string literal instead, so that you don't need to double all the backslashes:

connString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\andrew\Documents\Vinyl0.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

Upvotes: 6

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174279

You are missing a back slash in front of the a of "andrew". It should look like this:

connString = "Data   Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\andrew\\Documents\\Vinyl0.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

Upvotes: 3

Related Questions