INSERT problem - julb

12-Jul-07 04:28:29
Hi everyone,

I just wrote a simple app to insert some data into a database. Here's
the code:

private void FillDB()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\test.mdf;Integrated
Security=True;User Instance=True";
conn.Open();
SqlCommand command;
int res;
command = new SqlCommand("INSERT \"test\" (col1, col2)
VALUES ('hallo', 'world')", conn);
res = command.ExecuteNonQuery();
conn.Close();
}

the problem is, that although the result value of ExecuteNonQuery() is
one (i.e. one row is affected) nothing was added into the DB!!!
Does anyone know what's going on here???

Thanks a lot in advance,
Julie
reply
 
 

INSERT problem - brian.twardzi

12-Jul-07 05:06:41
Named pipe, check...
Integrated security, check...
Insert syntax is correct...

@_@ I have no idea...I blame SQL Express.
reply
 

INSERT problem - Tibor Karaszi

12-Jul-07 05:11:57
I'd use a Profiler trace to see what is actually submitted to SQL Server. I haven't worked with
attached databases this way, though...

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
reply
 

INSERT problem - M

12-Jul-07 05:12:06
How have you verified that no data exists? Are you connecting to the same
database?


ML

---
http://milambda.blogspot.com/
reply
 

INSERT problem - Juliane Bach

12-Jul-07 05:48:00
yes I am... I created the database within VS2005 and use the connection
string that was generated by Visual Studio. Anyhow, there is no other DB
with that name on my hard drive.
reply
 

INSERT problem - Tibor Karaszi

13-Jul-07 02:16:26
How about schema? I suggest you schema qualify the object name...

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
reply
 

INSERT problem - julb

13-Jul-07 04:39:42
Hi Tibor,

sorry... I'm quite experienced to programming but a newbie to
databases... what do you mean by schema qualifying what object name?
I think that there may be I rights problem... but i dont know what it
could be... I am able to make queries, however... just insert, update,
create table etc. don't work...
reply
 

INSERT problem - M

13-Jul-07 04:54:00
In your query:

INSERT test (col1, col2)
VALUES ('hallo', 'world')

...the name of the destination object (table? view?) "test" is not
schema-qualified (e.g. dbo.test). Perhaps the object exists in more schemas
than one?

Also check your permissions.


ML

---
http://milambda.blogspot.com/
reply
 

INSERT problem - julb

13-Jul-07 05:12:52
I don't think that this is the problem, as a select query works this
way, but I'm gonna check it...


I guess, that the problem has something to do with permissions, but as
I posted, I've no idea on where to look and check them...

Julie
reply
 
Huge difference between estimated and actual row count
promotion
Silverlight    WPF    WCF    WWF    LINQ   
JavaScript    AJAX    ASP.NET    XAML   
C#    VB.NET    VB 6.0    GDI+    IIS    XML   
.NET Generics    Anonymous Methods    Delegate   
Visual Studio .NET    Expression Blend    Virus   
Windows Vista    Windows XP    Windows Update   
Windows 2003 Server    Windows 2008 Server   
SQL Server    Microsoft Excel    Microsoft Word   
SharePoint    BizTalk    Virtual Earth   
.NET Compact Framework    Web Service   

"Everything" RSS / ATOM Feed Parser
How to send and receive messages through message queuing in .Net
How to Read text file as database
SQL Server 2005 Paging Performance Tip
Display code of web page.
Fully Scalable Excel File Importer class for .net using Microsoft Jet driver
Generic Chart Color Manager class that can be used for any charts
Helper class to style the infragistics wingrid
Using Reflection to detemine as Assembly Info in and out.
Helper class to play with Window (Owners and position)
Resolving displayname from the culture using the XmlLanguage and LanguageSpecificStringDictionary class