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.
Add a LINQ to SQL .dbml item to my project
Connect to a database in Server Explorer
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:
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.
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.
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.
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.
Related
I’m really confused with how to use database projects in Visual Studio (2019).
I’ve created a new project and imported my database into it. I then can happily edit the SQL and commit it into source control, however, when I try to deploy the items to the server it fails due to unresolved references.
To get around this I have added in a reference to my database and changed the SQL to use the reference like so:
SELECT * FROM [$(DataBase)].dbo.TableName
The project then builds and I can deploy the SQL to my server with:
Tools> SQL server > New Schema Comparison
However what do I then do if I want to edit that SQL and make any changes?
Currently I’m using the “open by default” feature to open the SQL into SSMS (as the editor in visual studio does not appear to have the ability to execute the sql), and then find and replacing the [$(Database)] text with my database name, then making and testing my changes and then cut and pasting it back into Visual Studio and find and replacing the [$(database)] text back in.
I can’t help but think that I'm surely missing something here‽ I find it hard to believe that the workflow is this longwinded.
I have a solution in Visual Studio 2013, where among the others I have also a Database project. This project contains some .sql written in T-SQL.
IntelliSence and Parse (SQL (on visual studio menu) > Parse) do not work. I have gone through this Troubleshooting guide and many question on SO, but nothing worked.
As I understand is something in project setting that I need to configure or some leftovers I need to clean.
Any suggestions ?
In brief
IntelliSence is enable
SQL CMD is Disabled
In SQL Server Explorer there is an entry (localdb)\ProjectsV12 containing my DB.
Other solutions opened on the same instance of visual studio work fine
ReSharper is installed but is not the issue (I also tried without it)
Note:
The solution (the one that has issues) was created in a previous version of Visual Studio.
Update 15/12/2015
After some digging I found out that the issue may has something to do with the .v12.suo file (which is located alongside with .sln file and is hidden). Copping this file from a similar solution (one that IntelliSence works) eliminates the problem.
Another workaround that it may help, is to go to the "Database Project" properties (right click on the project in Solution Explorer and then select Properties), on the Debug tab and press Restore Default in "Target Connection String". In my case this just changes the Initial Catalog= value to Database and like "magic" IntelliSence works again! (in some cases it may need to restart the Visual Studio)
After this even if I restore (using Edit) the "Target Connection String" to the previous values the IntelliSence continues to work.
Previously I developed everything DB related in SSMS but since I didn't have it setup with any source control I decided to move it into Visual Studio (where I develop everything else) as a Database Project.
This works quite well for most things but I would like to test and debug my stored procedures somehow without publishing the project. Is this possible and how is it done? The important thing is that data from the production DB should be accesible for the stored procedures.
From Visual Studio, open SQL Server Object Explorer (View-SQL Server Object Explorer). Find your database, right click and select "New Query".
You can run/test your sp using "exec spProcedureName".
You can use "Ctrl-Shift-E" as a shortcut to execute query.
Also, you can find your procedure under "Programmability-Stored procedures" and right click on it. If procedure has parameters, you'll get a pop-up window in order to enter params.
Hi I am new to database concepts and database related programming. Now I want to create a local database in my application. I am using Visual studio 2012 for simple adesktop based application. I have created a local Database "PersonDatabase.sdf" and its shows in server explorer too. Now doing some Google I come to know that I need to create a .dbmlfile like PersonDatabase.dbml in my solution explorer.
I did add -> new items -> LINQ to SQL Classes and it's also showing in the solution explorer. But in the Object relational designer I can not drag and drop the already available databases. It shows "the selected object(s) use an unsupported data provider ".
I Google it find that I need to create it manually using sqlClient.exe available in C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools in Windows 8 Pro with VS 2012. When I am inside the folder "NETFX 4.0" I run the following command "sqlMetal.exe PersonDatabase.sdf /dbml:PersonDatabase.dbml". But in the command prompt it says PersonDatabse.sdf doesnot exist. then I give the entire path but due to the space issue in "Visual Studio" it does not execute. Finally I did like this
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools>SqlMetal
.exe #"C:\Users\kumar\Docs\Visual Studio 2012\Projects\Junk\DBMLDatabaseConn
ection\DBMLDatabaseConnection\PersonDatabase.sdf" /dbml:#"C:\Users\kumar\Docs\Visual Studio 2012\Projects\Junk\DBMLDatabaseConnection\DBMLDatabaseConnection\PersonDatabase.dbml"
But it says that PersonDatabase.sdf doesnot exist. But it exist in that directory. I have gone thorugh few sites they also said that same procedure. Am I doing something wrong? Can this be done? One more question is what is the role of dbml to connect to sdf here?
Thanks
Syntax to do the same is slightly different Use following syntax :
SqlMetal /dbml:PersonDatabase.sdf PersonDatabase.dbml
I have a SQL project in my .Net project in Visual Studio 2010. I added it to my solution because I thought it will help me to create all the database objects in more environment without difficulties.
My scope is to create/define the database objects (tables and stored procedures) in more computers, easily.For this purpose I created an Sql project in visual studio and I added for each table and stored procedure the creation script in this project. Now I have 30 scripts and I'd like to run it on a new sql instance.
If I open each sql file I have, in visual studio, an toolbat that allows me to tun the opened file on a sql instance (I have an connect button) and this generates the proper object (table or SP).
The question is: how do I do to run all the files in this project in one click. How to create all the objects in one click? Now I have about 30 scripts to run, and I need a proper way.
The way I tried to do it was to set as default project the sql project and to press run (F5), but then I got some strange compilation errors in sql files, errors witch didn't was there when I run (execute) each script individually.
Here is the right click menu for this project (No Run, Publish or something else!):
I tried to use from that menu the Deploy command. The bad news (for me) is that I got this on that command:
I don't have any error in my sql scripts, each one runs correctly.
Thank you.
Use need to deploy your project onto a database thus use the Deploy menu item.
The way database projects work, is that they compare the schema in the project to the schema at the destination.
What this means is you shouldn't have an use statements, or alter statements, ect...
What does one of those procs look like that is throwing the error?