L
Lloyd Dupont
I'm trying to create a SqlServer express database file on the fly in a web
application..
(mhh.... maybe I should try to get something running in a desktop
application first?)
Anyway I want to connect to a database file and, if it doesn't exist, create
the DB on the fly.
Actuall I'm trying to create the connection like that:
I'm trying to create a connection like that:
===
public static SqlConnection GetConnection(string filename)
{
string connString = @"Data
Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|{0}.mdf;Integrated
Security=True;User Instance=True";
connString = string.Format(connString, filename);
SqlConnection sqlc = new SqlConnection(filename); // <= exception here
return sqlc;
}
===
It fails with "Format of the initialization string does not conform to
specification starting at index 0."
mmh..
is it because the file doesn't exists?
How am I to connect to SqlServer to run the SqlSever creation script if my
file doesn't exist?
Should I embed an empty database as a resource in my control library if I
want to automatically create the database?
Or is there an other way? (I have the creation Sql script ready, I just
wonder how to run it)....
application..
(mhh.... maybe I should try to get something running in a desktop
application first?)
Anyway I want to connect to a database file and, if it doesn't exist, create
the DB on the fly.
Actuall I'm trying to create the connection like that:
I'm trying to create a connection like that:
===
public static SqlConnection GetConnection(string filename)
{
string connString = @"Data
Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|{0}.mdf;Integrated
Security=True;User Instance=True";
connString = string.Format(connString, filename);
SqlConnection sqlc = new SqlConnection(filename); // <= exception here
return sqlc;
}
===
It fails with "Format of the initialization string does not conform to
specification starting at index 0."
mmh..
is it because the file doesn't exists?
How am I to connect to SqlServer to run the SqlSever creation script if my
file doesn't exist?
Should I embed an empty database as a resource in my control library if I
want to automatically create the database?
Or is there an other way? (I have the creation Sql script ready, I just
wonder how to run it)....