sql71501 sql parameter has unresolved reference to build-in type - visual-studio-2012

from VS2012 I created a Database project and created ad custom type
CREATE TYPE dbo.TypeProductCategoryTable AS TABLE
( ProductID int, CategoryID int )
Now when I write stored procedure with using this type, i get compile error
sql71501 sql parameter has unresolved reference to build-in type
Procedure
CREATE PROCEDURE [dbo].[usp_ProductCategory_Mapping]
#tvProdCat dbo.ProductCategoryTableType READONLY
AS
insert into tProductCategories(ProductId,CategoryId)
SELECT #tvProdCat
RETURN 0
How to handle this? Can we create custom type on Visual studio Database project

you can use pre-deployment script in visual studio project.
for doing this you need to add 2 files in VS:
1.
create UserDefinedTableType.sql in your database project in VS and put the scrip of creating table type inside this script.
2.in your database project add UserScripts -> pre-Deployment script and call the script in the step 1 here . using this code :
:r .\Scripts\Pre-Deployment\UserDefinedTableType.sql
the unresolved reference will be resolved with this solution

I had this issue and realized that somehow the build node for the TVP was inserted below the SP where it was used within my .sqlproj file. once I moved the TVP above the SP I no longer received the error in VS and the project deployed as expected with no errors.
I had not realized previously that the order of the build nodes in the .sqlproj mattered but apparently the the DACPAC Compiler wasn't built to intelligently determine the order of the build process which makes sense in retrospect. I'd rather have that control even if it did in this case trip me up.

Related

Database References on Deploy

I have (several) database project in a solution. In one I have a referesnce to a dacpac (this is ACTUALLY a copy of one of the main databases as we take a SQL snapshot at end of day and some code needs to reference this (DBANME_Daily) rather that DBNAME).
now this builds correctly, the code with SELECT * FROM DBNAME_DAILY.schema.table all compiles and builds with no error.
ON deployment however I get the unresolved reference to DBNAME_DAILY.schema.table
You want to add a dacpac for that database as a reference, using variables for the database. Should be different database, different names. You'd then use that variable in your code and you'd pass in the variable name for your build/publish tasks depending on the environment.
This is a little older article, but still pretty accurate:
http://schottsql.com/2012/10/31/ssdt-external-database-references/
You can tweak that a little bit using a variable for the database name. When I wrote this, it was mostly just a different database with the same name across environments. For your case, you'd just use the DB variable. Then replace your "DBName.schema." with "[$DBNameVariable].schema." (or something similar)
Sorted, my mistake was the dacpac reference would only allow the project to BUILD. For deployment the database DBNAME_DAILY MUST EXIST.
Lesson Learnt.

Bcp must be installed error when loading Adventureworks Azure datawarehouse

I'm trying to test the Azure Data Warehouse. I successfully created and connected to the database, but I've run into a snag as I attempt to load the tables. I'm trying to execute the following instructions:
To install AdventureWorksSQLDW2012:
-----------------------------------
4. Extract files from AdventureWorksSQLDW2012.zip file into a directory.
5. Edit aw_create.bat setting the following variables:
a. server=<servername> from step 1. e.g. mylogicalserver.database.windows.net
b. user=<username> from step 1 or another user with proper permissions
c. password=<passwordname> for user in step 5b
d. database=<database> created in step 1
e. schema=<schema> this schema will be created if it does not yet exist
6. Run aw_create.bat from a cmd prompt, running from the directory where the files were unzipped to.
This script will...
a. Drop any Adventure Works tables or views that already exist in the schema
b. Create the Adventure Works tables and views in the schema specified
c. Load each table using bcp
d. Validate the row counts for each table
e. Collect statistics on every column for each table
I completed the prerequisites of installing bcp and sqlcmd and used the -? command to confirm the installations.
Unfortunately, when I try to complete step 6 above I get the following error:
REM AdventureWorksSQLDW2012 sample database version 3.0 for DW Service Tue 06/27/2017 20:31:01.99 Bcp must be installed.
Has anyone else come across this error or can anyone suggest a potential solution.
UPDATE: I've also copied the path where BCP is located to my path environment variables. Still no luck.
The aw_create.bat contains a line where you need to provide the path of the bcp program. Once provided ans save the script worked like a charm.

Error: A namespace cannot directly contain members such as fields EntityFramework.dll' could not be found

enter image description hereI want to create model: add > class > ado.net entity, for my db first project and also want to create CRUD operation by asp.netscaffolding, but failed to create a model with necessary code.and thus i failed to create scaffolding .
in my model file AllahHelp.Context.cs, there is no code, only the text "ErrorGeneratingOutput".
Error 1:
A namespace cannot directly contain members such as fields or methods F:\project\WebApplication8\WebApplication8\Models\AllahHelp.Context.cs 1 1 WebApplication8
Error 2:
Compiling transformation: Metadata file 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools..\IDE\EntityFramework.dll' could not be found F:\project\WebApplication8\WebApplication8\Models\AllahHelp.tt 1 1 WebApplication8
If there is an error transforming your .tt files into class files, your class files will just have "ErrorGeneratingOutput" in the source file, which causes a "namespace cannot directly contain members such as fields" error, but doesn't really have anything to do with that.
Your actual error sounds like you're missing a reference to EntityFramework.dll. Right click the project, choose "Manage NuGet Packages..." and find and install EntityFramework to your project.
In some situations I've also run into a problem where since the transformation occurs before files are copied, referenced dlls don't ever get copied since the error occurs and stops the process. In this case you would need to remove the model from your project temporarily, successfully compile the project, and then add the model back.
According to this similar question it could also be because of your install path. If that is your issue, try to find where the dll is, and correct the environment variable VS120COMNTOOLS (Control Panel -> System -> Advanced System Settings -> Environment Variables -> System Variables)
(Be careful changing system variables, though.)
I was getting this error when attempting to build a project using .tt templates. I fixed the issue by checking everywhere that I used C# code injection and making sure that I closed each section of C# code by including #>.
Example:
Problematic code:
{
"find": "__LOCATION__",
"replaceWith": "<#= deployment.Location"
},
Fixed code:
{
"find": "__LOCATION__",
"replaceWith": "<#= deployment.Location #>"
},

How can I reference another DB from a VS DB project?

We have several databases, say DB1, DB2, DB3 etc.
They have to have identical code base, so we use a DB project in Visual Studio 2012 and generate a SQL script for deployment based on comparison between the project and UAT/Prod DB1. Then this script is applied to DB1-DBn.
For the very first time in the history of this DB project I had to create a function that contained a hardcoded database name, example:
inner join DB1.schema.table1 as t1 on
And now the project cannot be built or comparison cannot be updated or script generated (Update and Generate Script buttons disabled) due to a number of errors pertaining to that database reference, as VS seems to believe that DB1 does not exist.
I tried to add a project level SQLCMD variable $(DB) and set it to DB1 default value and use it as
inner join [$(DB1)].schema.table1 as t1 on
to work around the errors, but it did not seem to make any difference.
Edit:
A suggestion was made to add a circular project reference to itself and assign to it the same variable I was trying to add manually, not sure how to accomplish that.
As per this article the reference should be added to a manually extracted .dacpac file as follows:
Extracted .dacpac file from the targed DB with the following command:
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\120\sqlpackage.exe" /SourcePassword:p /SourceUser:u /Action:Extract /ssn:192.168.2.1 /sdn:DB1 /tf:DB1.dacpac
Included that as a database reference. It automatically assigned the correct SQLCMD variable name and the error disappeared.
From the source control point, even though when adding a database reference to a .dacpac file automatically creates a SQLCMD variable, it does not add the file to the project. The .dacpac file used still has to be added to the project as an existing item, which is kind of lame. Doing that in the solution explorer I encountered an error and had to do that through the team explorer instead, where that worked.

Not able to run... Errors

After running "Run Custom Tool" on the .tt dropped on my VS2k8 prj I'm not able to run my program.. shows 8 errors like:
Error 23 The type 'SouthWind.LanguageText' already contains a definition for 'KeyName' C:\Documents and Settings\Administrador\Meus documentos\Visual Studio 2008\Projects\WindowsFormsApplication4\WindowsFormsApplication4\ActiveRecord.cs 41320 23 WindowsFormsApplication4
Error 30 Ambiguity between 'SouthWind.LanguageText.KeyName()' and 'SouthWind.LanguageText.KeyName' C:\Documents and Settings\Administrador\Meus documentos\Visual Studio 2008\Projects\WindowsFormsApplication4\WindowsFormsApplication4\ActiveRecord.cs 41243 25 WindowsFormsApplication4
...
... and others
Any problem on my DB? Can you help me? Using MS SQL 2008
I'd also like to know if there's a need to create a new table/column, should the .tts runs again to update the classes?
I'm a OR/M newbie! Thanks
KeyName is the name of a method in the IActiveRecord interface so this is probably conflicting with the name of a column in your LanguageText table. If you rename the column then you should be OK.
Once you're renamed the column you will need to run the .tt files again for your changes to be picked up.

Resources