G
Guest
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"";Integrated
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.
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"";Integrated
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.