| Author |
Topic  |
|
|
asher
Starting Member
Netherlands
36 Posts |
Posted - 12/21/2012 : 05:43:50
|
I created a database using this code: string connection_string = @"Data Source=.\SQLExpress;Integrated Security=true;AttachDbFilename=C:\NewDatabase\NewTest2.mdf;User Instance=true;"; (having been gratefully advised that this is the right way). The database creation was successful in as much that the the database appears in the directory. I used the same connection string in the code to create a table and to read and write to it. Running the code, I get the same (reading and writing) error, namely " invalid object name 'Customer2' " Can anyone suggest a reason for this?
Asher.
|
Edited by - asher on 12/21/2012 07:34:03
|
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47040 Posts |
Posted - 12/21/2012 : 06:34:16
|
do you've the table Customer2 in attached db?
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
asher
Starting Member
Netherlands
36 Posts |
Posted - 12/21/2012 : 06:47:20
|
quote: Originally posted by visakh16
do you've the table Customer2 in attached db?
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
Yes the table was created in the database being written to and read from. Table creation, writing and reading is being attempted with the connection string as posted previously. Reading is being attempted like so: cmnd.CommandText = "SELECT name, company,street,pobox,city,telephone,email,customer_key FROM Customers2 WHERE customer_key LIKE search_argument";
Asher. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47040 Posts |
Posted - 12/21/2012 : 06:54:23
|
the only reason i would reckon getting that error is either table doesnt exist or is not created on your default schema
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
asher
Starting Member
Netherlands
36 Posts |
Posted - 12/21/2012 : 07:03:16
|
quote: Originally posted by visakh16
the only reason i would reckon getting that error is either table doesnt exist or is not created on your default schema
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
The table was created like so:
(Any good?)
using System.IO;
namespace FilesAndDatabase { public sealed class CustomerCreateTable { public CustomerCreateTable() { try { if (Directory.Exists(@"c:\NewDatabase\")) { new Warning("Now creating a Customers table."); string connection_string = @"Data Source=.\SQLExpress;Integrated Security=true;AttachDbFilename=C:\NewDatabase\NewTest2.mdf;User Instance=true;"; SqlConnection connection = new SqlConnection(connection_string); connection.Open(); SqlCommand command = new SqlCommand(); command.CommandText = "CREATE TABLE Customers2" + "(name VARCHAR," + "company VARCHAR," + "street VARCHAR," + "pobox VARCHAR," + "city VARCHAR," + "telephone VARCHAR," + "email VARCHAR," + "customer_key VARCHAR NOT NULL," + "PRIMARY KEY(customer_key))"; command.Connection = connection; command.ExecuteNonQuery(); connection.Close(); new TableAvailabilityWrite(); } } catch (Exception x) { new Warning("Table creation: " + x.Message); } } } }
|
 |
|
|
asher
Starting Member
Netherlands
36 Posts |
Posted - 12/21/2012 : 07:11:24
|
| PS I snipped a couple of usings. |
 |
|
| |
Topic  |
|