I'm trying to use a Data-Tier application involving a linked server and running into an odd problem.
Here's what I have:
1) A VS2010 solution which includes a Data-Tier project.
2) The Data-Tier project targets an SQL 2008 R2 server.
3) The SQL server has a working linked server connection to an Oracle database.
4) Views within the Data-Tier project reference the linked server using OPENQUERY
The linked server connection is valid, running queries against it on the server work fine, and creating the views directly on the server works fine as well.
However, whenever I attempt to build my Data-Tier application I get the following error:
SQL03006: View: [dbo].[vwMyExampleView] has an unresolved reference to object [MyExampleLinkedServer].
Essentially the problem is that the SQL Server Database project doesn't have a way to resolve the Link to the Oracle database's tables.
I had a similar problem when trying to reference a table in a different database on the same server. In my case I was using SQL Server for both databases, and created a database project for the other database, added it to the solution for the first project, then created a reference to the second project from the first. I also used SQLCMD variables in synonyms so that I would be able to change the synonym, and all my proc and view references would not need to be updated.
I'm not sure this will work between SQL Server and Oracle since the Visual Studio database edition only supports SQL Server. (AFAIK) You may be able to find a solution by creating a .dbschema file and adding the Database reference to your SQL Server project.
More details can be found at this link:
http://msdn.microsoft.com/en-us/library/bb386242.aspx
In SQL 2012, just add new item-> Server Objects - > LinkServer, add the sp code that creates link server, you are good to go
Related
I'm currently using Visual Studio to develop an ASP.NET/C# web application that relies on a SQL Server database for the data behind. From the moment I originally created the Data Connection through VS, I've gone back and changed certain things in the DB (certain column types, added test rows, etc) through SQL Server Management Studio. However, none of these changes are reflected in the VS application, which is a pain because I am constantly getting errors because of the mismatch. For example, I tried to insert a string into a column that was originally an int and I get an error when trying to process the query through my code behind, even though the actual DB lets me run the query just fine through SQL Server Manager.
This mismatch is so bad that if I run the same query (SELECT * FROM Project) on both SQL Server Manager and Visual Studio I get completely different results: SQL Server Management Studio vs Visual Studio
I've tried refreshing my connection on Server Explorer to no end and even created a new connection string on Web.config to see if this would somehow fix it, but nothing seems to work. I found an article that explains that VS creates a local version of the DB during the build, but it seems like the solution it provides only works for non-ASP.NET projects because I don't have a bin/Debug DB.
Any suggestions to get Visual Studio to reflect the latest version of my schema/data? Thank you!
From your example files, you are working on two different databases.
Execute the following command in SQL Server Management Studio and in Visual Studio. You will likely see that the filenames listed are different.
exec sp_helpfile
If so, then you are not connecting to the same server/database in both environments. You can click on the database in Visual Studio to see the "Connection string" in the Properties window. Check it against your web.config connection string.
I have followed through a tutorial using a "Code First" approach with Entity framework. It seems like Visual Studio was smart enough to create the database for me and setup the tables and everything based on my classes. I have a question about the database that was created.
I notice that the database was automatically set up and I could see it in my Server Explorer window in Visual Studio. In my Web.config, under the connection string, I see Data Source=(localdb)\v11.0;.... There is also a .mdf file created in a folder called App_Data.
My question is:
Was Entity framework using MS SQL Server or SQL Express for the database it has created?
If it wasn't using MS SQL Server or SQL Express, what was the database that Entity used?
I don't remember installing SQL Server or SQL Express. Does installing Visual Studio automatically install MS SQL Server or SQL Server Express?
PS: I will appreciate if you can help me to clear up my doubts. Coming from a PHP background, I'm very new to .NET and its ecosystem.
The connection string indicate that you are using SQL Server Local DB.
With Microsoft SQL Server 2012, Microsoft has introduced a feature called LocalDB which is a new edition of SQL Express. LocalDB is created specifically for developers and it is much easier to install (no service) and manage than standard editions. Developers initiate a connection by using a special connection string. It supports AttachDbFileName property, which allows you to specify a database file location.
When connecting, the server is automatically created and started, enabling the application to use the database without complex configuration tasks. This edition uses the same sqlservr.exe as the regular SQL Express and other editions of SQL Server.
http://msdn.microsoft.com/en-US/evalcenter/dn434042.aspx
http://technet.microsoft.com/en-us/library/hh212961.aspx
I installed adventure works, and I followed the instructions on this page:
How to: Create Connections to SQL Server Databases
basically nothing appears in the drop down, in step 2.
I cant even attach the database without getting an error, nor drag it to the web form.
It tells me that the database cant be attached cause it is version 705, and the server supports version 655..
Also what is teh difference between attaching the database and connecting to it?
I went to the installation center of 2008, and clicked on show installation info..I got this:
Microsoft SQL Server 2008 Setup Discovery Report
Product Instance Instance ID Feature Language Edition Version Clustered
Sql Server 2008 SQLEXPRESS MSSQL10.SQLEXPRESS Database Engine Services
1033 Express Edition 10.1.2531.0 No Sql Server
2008 SQLEXPRESS MSSQL10.SQLEXPRESS SQL Server Replication 1033 Express
Edition 10.1.2531.0 No
so I guess it is installed on my computer, but I cant access the application
You need the database to exist in an instance of SQL Server (or whatever RDBMS you so choose...but most likely, SQL Server). To do this you can do a few things: namely restore a *.bak database backup file of AdventureWorks, or you can attached the mdf and ldf files (database data and log files) to get your database online.
basically nothing appears in the drop down
Do you have an instance of SQL Server installed on your machine?
Also what is teh difference between attaching the database and connecting to it?
Attaching the database is using mdf and ldf files to get your database online ready for transactions. Connecting to the database is creating a connection between a client application and the aforementioned database. Two very different steps of the data access process.
Attaching to a database is necessary when the database file(s) are in a location other than the default location. You don't really "connect" to a specific database per se. You connect to a sql server instance which contains a list of databases on that instance (or referenced by the instance).
I have an ASP.NET project that also uses a SQL MDF File. My target server is SQL 2008R2 or SQL Azure.
I would like to know what deployment options I have as I migrate from DEV to PROD. In case it matters I'm not under any regulation to maintain PII or similarly private data.
How do I move my test schema and perhaps data to production?
You can move the entire database, including the data by attaching the MDF file to the new SQL server. Otherwise you can select all objects and generate CREATE scripts to copy the schema over.
Yes, you can attach to the MDF file directly, or do a backup / restore to get it over to SQL Server 2008.
I haven't played with SQL Azure... From what little I've heard I think you might be stuck scripting the data as durilai suggested (last I heard we're not allowed to do backups / restores for SQL Azure).
In SQL Server Management tools, right click on the database and click 'Script Database As' to create an SQL script for your database. You can also do something similar at the table level if you want the data.
I come from a linux/apache/php/mysql background. For my current project, I am forced to write web services using ASP.NET. I have installed visual studio and created an ASP.NET web service project. The web service I'm creating will use a SQL database backend. I see that visual studio installed "SQL Server Express 2008." I can see that there is a service called "SQL Server (SQLEXPRESS)" that is running. My question is, how do I run queries against this database? Where's the front end? What tool do I use to create databases and tables? Is there something else I have to install?
I feel completely lost and my google-fu fails me. There are so many different SQL products from microsoft that I can't tell what is the easiest path to just having a simple database with tables I can query from my development machine. With MySQL, I would install the MySQL database, download MySQL query browser and start firing queries at it. How can I do that with Visual Studio/SQL Server Express?
You can download SQL Server Management Studio from here. This is the GUI for working with SQL Server. It will let you create databases, tables, stored procedures, etc. as well as writing queries and manually edit data in the tables.
Aside from SQL Server Management Studio, you can use the Server Explorer tab in Visual Studio (by default on the right side, next to Solution Explorer) to add a data connection. You can do most of the most common database tasks (create/query tables, create views, etc) from there.
there's a command line tool that installs with SQL Server (all versions) called SQLCMD.exe, should be in your install path.
Visual Studio also lets you create dbs, run queries, look at table structures and data (including creating and deleting them, etc), you do that by opening your Server explorer window and making a connection to your local instance (.\SQLExpress by default).
Finally, as the other person mentioned, SQL Server Management Studio Express is a free download, and well worth the time it takes to install.