Pregunta

Me han cambiado el nombre de una tabla en una base de datos SQL Server 2008, desde eL_CourseStepUserNotes a StepUserNotes. Me cambió el nombre de la tabla utilizando el AMSS.

La tabla se utiliza en un 4,0 aplicación ASP.NET. Yo uso de LINQ a SQL para todos CRUD. El problema es que el código siguiente:

    dbDataContext db = new dbDataContext();
    var k = (from c in db.StepUserNotes
             where ((c.CourseStepFK == q.CourseStepFK) && (c.UserFK == q.UserFK))
             select c).FirstOrDefault();
    try
    {
        db.StepUserNotes.InsertOnSubmit(q);
        db.SubmitChanges();
    }
    catch
    {

    }

se produce un error en la línea db.SubmitChanges, diciendo:

SqlException was caught. Invalid object name 'eL_CourseStepUserNotes'.

Es decir, el antiguo nombre de la tabla tiene que volver a atormentarme.

He suprimido el antiguo archivo de LINQ a SQL dbml y ha creado una nueva. He buscado a través de todo el código fuente para cadenas que contienen el nombre de la tabla de edad. Nada. El código se compila ...

¿Dónde puedo consultar?

El error está regresando de SQL Server, y el uso de la utilidad para la inclusión de todas las claves externas de una base de datos de SQL Server se muestra en la pregunta SO: SQL:? necesidad de cambiar la restricción en la mesa de cambio de nombre

revela ningún signo de la antigua nombre de tabla en FKs tampoco.

Estoy en una pérdida completa en cuanto a dónde mirar o qué intentar después. ¿Alguna sugerencia?

¿Fue útil?

Solución

Respuesta:

El problema, según lo declarado por Stu y Stark fue un disparador. Stu me dio el SQL para ejecutar ese clavado el problema. Está documentado aquí en caso de que alguien se ejecuta en otro lugar esto:

Select Object_Name(ID) From SysComments 
       Where Text Like '%el_CourseStepUserNotes%'

Esto reveló un disparador con el siguiente nombre:

tr_eL_CourseStepUserNotes

El disparador hace referencia el nombre antiguo de la siguiente manera:

SET DateAmended = CURRENT_TIMESTAMP
     FROM eL_CourseStepUserNotes PP  
            INNER JOIN inserted i  ON PP.UserNoteId = i.UserNoteId

Ahora todo está funcionando de nuevo.

Me tonto, me he dado cuenta de que un disparador fue el problema, ya que el primer error me estaba relacionada con el campo DateAmended.

No tengo ni idea de por qué un disparador actualizaría cuando un nombre de tabla cambió. Me había registrado todas las claves y las relaciones, pero se olvidó de este disparador.

En vivo y aprender.

Otros consejos

When you recreated your linq to sql file, did you remember to refresh the server browser to reflect the table name change first?

Edit - I mean the visual studio server browser.

you need to rebind your LINQ To SQL class, drop all the tables, then add them again from the Server Explorer

  1. open your project in visual studio.
  2. open your dbml file.
  3. find the table you just have renamed.
  4. select and delete it.
  5. Save.
  6. Open server Explorer.
  7. Connect to your database.
  8. Find the table which you have renamed.
  9. Drag and drop on the designer of your dbml file.
  10. Save the file again.
  11. Compile your project.

It is not necessary to drop the tables from your DBML file. You can simply open the designer, click on the class diagram representing your table and type the new name of the table.

However, if you're recreating from scratch it is important to refresh in Server Explorer otherwise it will still pull the old name from the schema.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top