Can't drag stored procedure onto dbml designer

2020-02-27 07:01发布

问题:

I'm trying to do a simple call to a database stored procedure from a C# application.

I'm following a guide like, e.g., this one or this one.

Both of these have the same basic steps.

  1. Add a LINQ to SQL .dbml item to my project
  2. Connect to a database in Server Explorer
  3. Drag a stored procedure from the Server Explorer onto my .dbml designer window

But step 3 doesn't work. I have my stored procedure and my designer window, but I can't drag the sproc. I don't get a plus sign, or a "not allowed" sign. It's just a non-dragable object.

I can't find another way to add my sproc to the .dbml file. And I can't find anyone else who has had this problem. Every source simply says to drag it over.

What could I be doing wrong here?

Screenshot:

回答1:

Turns out the solution was that I had the wrong version of a .dll for Visual Studio.

I noticed I was getting exceptions when performing actions in the Server Explorer. Googling the exceptions led to this question which points to this dll

C:\Program Files (x86)\Common Files\microsoft shared\Visual Database Tools\dsref80.dll

as the issue.

I replaced it with the corresponding copy from one of my teammates and it now works fine.



回答2:

I had also installed VS 11 Beta and the designer was working fine until I uninstalled it. I had to delete the DLL manually at the above location and repair the installation by finding Visual Studio 2010 in Programs and Features and selecting Uninstall/Change and then Repair. The installer will replace the DLL file that was deleted with the correct version.



回答3:

For anyone that can drag the sproc, but sees no result (the sproc simply does not show up in the functions pane): make sure that the sproc only returns datatypes that L2S understands. For example you can not return a geography field.



回答4:

Editing .dbml files with a designer surface requires the LINQ to SQL tools which are not installed by default as part of any of the workloads of Visual Studio 2017. It can be installed by selecting the "LINQ to SQL tools" item under the "Code Tools" category in the "Individual Components" tab of the Visual Studio installer.