Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit not working with MSSQL

5 REPLIES 5
Reply
Message 1 of 6
roma_petrovich_2023
806 Views, 5 Replies

Revit not working with MSSQL

In my project, I need to implement user registration through WPF which runs in Revit. When trying to send a query or get data from MSSQL, a critical error occurs and Revit closes. At the same time, the same code that works with MSSQL works flawlessly in applications that are not related to Revit in any way. Is there a way how to solve this problem?

5 REPLIES 5
Message 2 of 6

Without a sample code is kinda hard to know exactly the problem. But most of the time if an Exception happens in a modeless WPF and is not resolved Revit crashes and closes.

 

One thing, you could do to test is create a IExternalCommand and run your MSSQL code in there, probably gonna work.

 

In the WPF use a try/catch to know what is happening, and remember Revit only allows access Revit method/class inside a Revit context (Same thread and safe place inside that thread).

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 3 of 6

Here is an example of the code

Message 4 of 6

Revit API only works with NET Framework.

 

  • Revit 2019 - .NET Framework 4.7
  • Revit 2020 - .NET Framework 4.7
  • Revit 2021 - .NET Framework 4.8
  • Revit 2022 - .NET Framework 4.8
  • Revit 2023 - .NET Framework 4.8
  • Revit 2024 - .NET Framework 4.8

This DbContext what package is come from?

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 5 of 6

The database is connected using the Entity framework.

1. Here, a connection to the database is made and data is added to it from the User class, which becomes a database table.
2. Here the address of the connection to the database is written
3.This is a class with fields
4. On the click of the button located on the WPF form, we create an instance of the User class, write it down and send it to the database.

As mentioned above, this code works properly outside of Revit, but in Revit it stops working and a critical error occurs

Message 6 of 6

You may find more information if you try handling corrupted state exceptions or first chance exceptions.

 

At the moment what you provided isn't much to go on. The majority of times this difference in behaviour is due to where add-in code base is vs standalone application. Revit add-in starts looking where the Revit executable is kept a standalone app will be starting to look where your assembly file is kept (likely where your referenced ones are also). Ordinarily if this is the issue you should only end up with a file not found exception/type load exception. However if one issue compounds/masks another you may not see that, you need to get more information.

 

You could even go as far as to p/invoke GetLastError it will give you an integer to lookup but again the timing is important i.e. when to call it: just after the error that causes it, just after the line that causes it. Also look in the Revit journal for clues.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community