How is Visual Studio 2010 connecting to SQL Server 2008 if I don't have the native client installed? - visual-studio-2010

I have MS VS 2010 installed on my Windows 7 but, I don't have the SQL Server Native client installed in it.
After loading Visual Studio I do click menu Data / Transact-SQL Editor / New Query Connection.
The SQL Server 2008 R2 login dialog will show up, I type server name, select SQL Server authentication, type username and password and click connect. The connection is established and an editor window shows up and I'm ready to query!
I understand the SQL Server 2008 native client files are sqlncli10.dll, sqlnclir10.rll. I did search for these files in my entire hard drive and they weren't found.
So, how is Visual Studio 2010 connecting to SQL Server 2008 if I don't have the native client installed?
Is VS 2010, when connecting to SQL Server 2008, using .NET Framework assemblies?

The .NET Framework already contains the Sql Server (and other) Database clients.
Have a look at System.Data.SqlClient

If NO native client is installed, Visual Studio 2010 is using the .NET Framework version 4.0 to connect to SQL Server 2008 R2 when connecting through menu Data/Transact-SQL Editor/New Query Connection.
I verified and it is loading assembly System.Data.dll (located under C:\Windows\Microsoft.NET\Framework\v4.0.30319) to establish the connection to the server.
I have not installed the Native client 10.0 for SQL Server 2008 R2 and I'm not using it right now but, if installed, the native client files (sqlncli10.dll, sqlnclir10.rll, and s10ch_sqlncli.chm) should be found under
%SYSTEMROOT%\system32\
which are installed as part of the SQL Server installation.
There is also a redistributable installation program named sqlncli.msi, which should be found on the SQL Server installation CD under
%CD%\Setup\
The reference for installation details
http://msdn.microsoft.com/en-us/library/ms131321.aspx
And the reference for the SQL Server 2008 R2 Native Client Features
http://msdn.microsoft.com/en-us/library/ms131456.aspx

The key piece of information here is:
You do not need to install SQL Server Native Client on your client machine (in this case your dev box where Visual Studio is), in order for an application using ADO.Net, to connect to SQL Server.
The reason is as #dknaack said: the .Net framework contains the code required to make the connection. This is contained in System.Data.SqlClient.
SQL Native Client on the other hand is used by unmanaged applications to connection to SQL Server via either OleDB or ODBC providers.
In short:
System.Data.SqlClient - used for connections from managed code to SQL Server i.e an ADO.Net connection
SQL Server Native Client - used for connections from unmanaged code to SQL Server
Whilst you CAN connect to SQL Server from a managed app using SQL Server Native Client, it is not a recommended practice:
If you are developing a new application, it is recommended that you
consider using ADO.NET and the .NET Framework Data Provider for SQL
Server instead of SQL Server Native Client to access all the new
features of recent versions of SQL Server.
References:
https://learn.microsoft.com/en-us/sql/relational-databases/native-client/sql-server-native-client-programming?view=sql-server-2017
https://learn.microsoft.com/en-us/sql/relational-databases/native-client/applications/using-ado-with-sql-server-native-client?view=sql-server-2017

Related

Oracle Data provider for .NET in visual studio

Newbi to oracle and its versions and .NET providers, but did some investigation.
I'm trying to add Oracle connection to the visual studio server Explorer (before setting up the Entity Framework 6 for oracle).
System preferences:
Windows 10 enterprise - 64 bit operating system
Visual Studio 2015
Oracle Data Access Components (ODAC) which includes Oracle developer Tools for Visual Studio: ODAC12C - 12.2.0.1 - it is suitable to 64 bit !
The DB is located in a remote machine and I can see the DB objects using the Oracle SQL developer. It uses the TNSNames file to locate the DBs.
when trying to "add connection" in the visual studio server explorer:
Select Data Source: Oracle DataBase
Data Provider:.NET framework data provider for Oracle.
It claims that:
"This provider is deprecated and should not be used. Instead download
Oracle Developer tools for visual studio for comprehensive integration
with Oracle database."
The problem is that the mentioned above reference links to a 32-bit Oracle Data Access Components (ODAC) bundle which includes "Oracle Developer Tools for Visual Studio". The same shXX happens when choosing .NET framework data provider for OLEDB.
Either I don't see the relevant provider in the list or there is a problem.
After inserting Server name, User name and Password in the "Add connection" dialog box, I get this error message:
"Attempt to load Oracle Client libraries threw BadImageFormatException.
This problem will occur when running 64 bit mode with the 32 bit Oracle Client components installed"
What am I doing wrong ?
Is this the way of defining connection string when I have a TNSNames file ?
Microsoft .NET Framework Data Provider for Oracle is different to Microsoft OLE DB Provider for Oracle which is different to Oracle Data Access (which can be Oracle Data Provider for .NET or Oracle Data Provider for .NET Managed Driver or Oracle Provider for OLE DB, depending on which one you installed), see How to connect to Oracle 11 database from . net
Visual Studio 2015 is 32-bit, when you like to connect to an Oracle database directly from Visual Studio Explorer then you have to download/install the 32-bit version of ODAC - and also install 32-bit Oracle Client.
In case you like to use also 64-bit Oracle Client and drivers follow this instruction: BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed

how i install mssqlcli on my windows 7 machine.

How can I install ms sql client on my windows 7 machine ?
Because without this driver error is "Provider cannot be found"
I am using mssql server 2005 on my Win XP, I am fail to install dot net framework 2 on windows 7 client.
Microsoft SQL Server Native Client contains the SQL OLE DB provider and SQL ODBC driver in one native dynamic link library (DLL) supporting applications using native-code APIs (ODBC, OLE DB and ADO) to Microsoft SQL Server.
Get the SQL Server Native Client for SQL Server 2005
https://www.microsoft.com/en-us/download/details.aspx?id=24793

Create setup file with SQL Server database in VB2010

I made a demo project in vb2010 using database interaction with SQL Server 2008 R2. Created a setup file for that project and installed and executed successfully on my PC. Copied that setup file on another PC and tried installing. But couldn't run it because SQL Server 2008 R2 was installed in that PC.
My question is that how can we create a setup file with database so that we need not install SQL Server 2008 R2..? Because, let's assume that I am developing a software for my client. What if my client doesn't have SQL Server installed on his PC? It will be useless to install the whole SQL Server for a small application. How can we achieve that?
It will be useless to install the whole SQL Server for a small application.
That's exactly right. Sql Server is not intended for use as a private data store for a single-user desktop application. If that's what you want, you can use Sql Server Compact Edition, Sql Server LocalDB, Sqlite, or even ~gasp~ MS Access. But don't use the full edition of Sql Server; not even Sql Server Express Edition. The full version of Sql Server is just that: a server, intended for use in a shared environment where you have many users talking to the same data source.

Connecting to end user's SQL Express during installation

I have been writing SQL Compact C# winforms applications for a while now, with the help from all the wizards in Visual Studio. The database is created during development, and installed as-is. Then suddenly, I realise I actually have no clue how to connect to SQL Express on client's machine and install a database if I had to.
There are many examples on connection string and creating database in SQL Express via code (C# in my case) but I don't think that is what I am looking for.
If I develop an application that requires SQL Express. I know there's a feature in Visual Studio that detects and install SQL Express if it does not exist. However, how do I set up and install my database in SQL Express? Do I need to somehow get credentials somewhere?
You mention both SQL Server Compact Edition and SQL Server Express Edition; these are two different things, but for the case you've described you probably mean SQL Server Compact Edition.
SQL Server CE comes with the .Net Framework, so no install should be required. However, you will have to create a database. You can do that with SqlCeEngine.CreateDatabase().
EDIT
For SQL Server Express... to get a connection string from the user without them having to actually type in a connection string, you can use a data connection dialog: archive.msdn.microsoft.com/Connection

Database "cannot be opened because it is version 661" when attaching .mdf file

I am trying to attach MvcMusicStore.mdf to my .\SQLEXPRESS instance (sql server version 10.0.2531) in sql server 2008 R2 management studio. I got the db from this project:
http://mvcsitemap.codeplex.com/releases/view/67151
When i am trying to attach i am getting an error?:
The database 'C:\PROJECTS\CODEPLEX\TFS10\MVCSITEMAP\BRANCHES\3.1.0\SRC\MVCSITEMAPPROVIDER\MVCMUSICSTORE\APP_DATA\MVCMUSICSTORE.MDF' cannot be opened because it is version 661. This server supports version 655 and earlier. A downgrade path is not supported.
Do I need to upgrade my sql server or what else?
Your SQL Server Express instance is version 2008 and the database is from 2008 R2. You'll have to upgrade to SQL Server Express 2008 R2 to restore the database. It doesn't matter that you are using the 2008 R2 version of Management Studio - the database instance needs to be updated as well.
See SQL Server: Attach incorrect version 661

Resources