How to connect dbml with the database? - database

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

Related

Visual Studio Database Project References

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.

Visual studio 2010 sql project - how to run?

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?

Can't drag stored procedure onto dbml designer

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.

Can't select "Build Solution"

I am getting trouble to use Build solution in Visual Studio.
I was building data cube and I needed to use Build solution to finalize my project.
However, I couldn't find Build solution from the Build menu.
For example ....
http://cfile7.uf.tistory.com/image/18493D524E2CF5A31F8B61
It should be like this then I can choose build solution option
However, when I tried on my laptop...
http://cfile8.uf.tistory.com/image/16493D524E2CF5A21E9D27
I was unable to find these options...
I am not really sure about my mistakes....
My data was built by SQL Server 2008 R2 and I was using Visual Studio (which came with SQL Server)
Does anybody know solution to this problem?
From the second screenshot that you posted, it looks like you don't have a solution open, just the project that was contained in the solution. A Visual Studio solution file is usually a .sln file, and if you open it up in Notepad you'll see that it's just an XML file which describes project(s) it contains (the actual project files are different, the solution just makes reference to the project filenames). Make sure you get the .sln file to your laptop and open that, not the project file.
Right click on the solution or Project node which is on the Solution-Explorer. There should be Build menu item.
Or may be the Visual Studio coming with SQL 2008 R2 doesn't have that functionality?

Calling a .Net Assembly from a SQL Server 2005 Reporting Services report?

I've currently got a set of reports with a number of common functions sitting in code blocks within the .rdl files. This obviously presents a maintainability issue and I as wondering if anyone knew a way for these different reports to share a library of common code?
Ideally I'd like to have a .Net Assembly attached to my Reporting Services project, which all of my reports can access and call functions from. This would save the headache of trying to update and redeploy about 100 reports every time a change needs to be made to a common function.
Any suggestions?
From within Visual Studio in the properties of the report, on the 'References' tab add the details for the assembly that contains the managed code. This code can be called from expressions within reports using the instance name that is specified.
This assembly can either be stored in the GAC or the PrivateAssemblies directory of Visual Studio, and be deployed to the Report Service 'bin' directory on the Reporting Services server. For more information refer to How to use custom assemblies or embedded code in Reporting Services
I had a lot of pain with this so I hope this helps someone. You can get it from the MSDN article but there are a few points below that I think can help speed someone through this a little faster.
Don't forget to add this to your rssrvpolicy.config file:
<CodeGroup class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="MyCodeGroup"
Description="Code group for my data processing extension">
<IMembershipCondition class="UrlMembershipCondition"
version="1"
Url="C:\pathtocustomassembly\customassembly.dll"
/>
</CodeGroup>
I forgot to do this and I was hating it for awhile.
Plus don't forget to hit both of the following folders for 2005 with your new dll:
Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies
Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin
Plus don't use log4net with your assembly. I couldn't make it work. Maybe someone can but not me.
Plus if you mess up like I did you won't be able to delete the files until you close Visual Studio.
Plus make your methods shared or static. It's easier.
Create a deployment batch file. Something like:
#ECHO OFF
REM Name: SRSDeploy_Local.bat
REM
REM This batch files copies my custom assembly to my Reporting Services folders.
REM
REM This is the SQL Server 2005 version:
copy "C:\Projects\Common\lib\SCI.Common.SSRSUtils.dll" "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies"
copy "C:\Projects\Common\lib\SCI.Common.SSRSUtils.dll" "C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer\bin"
Finally, build your report before previewing.
If it builds you're likely on your way.
Except...
You can't deploy it to your production report server because you'll always get the following error:
Error while loading code module
Which is what I'm working on right now.
The following article lists just about all the different ways of calling .Net code from an SSRS report. Extending Microsoft SQL Server 2000 Reporting Services with Custom Code
If all these reports run against the same server, another option to consider would be to use .Net stored procedures in the database to hold your code.
Many thanks guys, I can now call my assembly from my reports.
Supplementary question:
Is there a namespace I can include when I'm creating my assembly that makes it aware of objects in the report designer such as fields and parameters? It'd be really great if I could pass, say, a collection of fields in a strongly-typed way to my assembly.
And the answer: A couple of hours of searching reveals that adding \Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\Microsoft.ReportingServices.ProcessingObjectModel.dll as a reference in my assembly allows me to access the various Reporting Services types, such as Fields and Parameters. Note that in Reporting Services 2008, the namespace changes.
You must deploy to the GAC.
http://www.developerdotstar.com/community/node/333

Resources