By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,996 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,996 IT Pros & Developers. It's quick & easy.

Literals possibly fouling connectionstring

P: n/a
I'm trying to connect to an Sql Express database and I'm not sure if my
problem is with the C# string expression or the connection string itself.
The code was originally working fine when connecting to an online MSSQL
database. Now I need to modify the code to work with a local server. Here's
the code:
SqlConnection cn = new SQLConnection();
cn.ConnectionString = @ConnectString=@"Data
Source=.\SQLEXPRESS;AttachDbFilename=""C:\VS
Projects\Personal Utilities\TableClassBuilder\FTTestLocal.mdf"";Inte grated
Security=True;User Instance=True";
cn.Open();

SqlCommand myCommand = new SqlCommand("Use FTTestLocal Create Table Asset
(AssetID int Identity Not Null Primary Key, AssetName varchar(150) Not Null,
Modified TimeStamp)", cn);

int ct = myCommand.ExecuteNonQuery();

When I run the application I get an error when the command is executed
stating "Could not locate entry in sysdatabases for database 'FTTestLocal'.
No entry found with that name. Make sure the name is entered correctly."

I also attempted to include the file extension .mdf in the SqlCommand. This
had no impact. The error message that appeared still only referrenced the
filename without the extension.

Thanks in advance for any help.
May 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
OK, the
cn.ConnectionString = @ConnectString=@"
syntax looks a bit bizarre (I'll assume that you have a "string
@ConnectString;" somewhere).

I'd give it a try without the "User Instance=True".

May 15 '06 #2

P: n/a
I'm trying to connect to an Sql Express database and I'm not sure if my
problem is with the C# string expression or the connection string itself.
The code was originally working fine when connecting to an online MSSQL
database. Now I need to modify the code to work with a local server. Here's
the code:

SqlConnection cn = new SQLConnection();

cn.ConnectString=@"Data Source=.\SQLEXPRESS;AttachDbFilename=""C:\VS
Projects\Personal Utilities\TableClassBuilder\FTTestLocal.mdf"";Inte grated
Security=True;User Instance=True";

cn.Open();

SqlCommand myCommand = new SqlCommand("Use FTTestLocal Create Table Asset
(AssetID int Identity Not Null Primary Key, AssetName varchar(150) Not Null,
Modified TimeStamp)", cn);

int ct = myCommand.ExecuteNonQuery();

When I run the application I get an error when the command is executed
stating "Could not locate entry in sysdatabases for database 'FTTestLocal'.
No entry found with that name. Make sure the name is entered correctly."

I also attempted to include the file extension .mdf in the SqlCommand. This
had no impact. The error message that appeared still only referrenced the
filename without the extension.

Thanks in advance for any help.
May 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.