Type provider cannot connect to localDB - sql-server

I have the following F# script. I copied the connection string from a working Asp.net Mvc project. However, it got the following error. The connection string should be correct since the Asp.Net Mvc project works fine. Or does F# type provider not accept the connection string?
#r "System.Data.Entity.dll"
#r "FSharp.Data.TypeProviders.dll"
#r "System.Data.Linq.dll"
open System.Data.Linq
open System.Data.Entity
open Microsoft.FSharp.Data.TypeProviders
type private EntityConnection = SqlEntityConnection<ConnectionString=
"Data Source=(LocalDb)\v11.0;Initial Catalog=MyDB;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MyDb.mdf",
Pluralize = true>
Script1.fsx(9,33): error FS3033: The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Error reading schema. error 7001: The provider did not return a ProviderManifestToken string. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) The network path was not found

You might want to check that v in v11.0, it's been known to cause some problems. Even if your connection isn't set to be case sensitive, try upper-casing it and see if it works: V11.0.

Related

SQL Connection String failing to connect SQL Instance

I am attempting to debug an application, but when I run it I get the following error message:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I've opened up the 1433 port and double-checked it's open and reachable from my current location. I've also enabled TCP/IP remote connections and can connect remotely using SQL Server Studio Manager.
The connection string I'm using is:
Data Source=xx.xx.xxx.xx, 1433;Network Library=DBMSSOCN;Initial Catalog=KnightOwl-Demo;Persist Security Info=True;User ID=KnightOwlGentleshaw; Password=xxxxxx
I'm 90%sure there's something wrong with the connection string but I'm not sure what?
If you are not sure about the Connection string, use a udl file for testing:
Create a new text file.
Change the extension to .udl (e.g. 1.txt to 1.udl)
Go to the Connection tab
Insert your credentials (Servername\instance , user name + password / Windows security etc)
Check the Allow saving password check box
Click on Test Connection and get a success message.
Click on OK (this will close the form)
Open the 1.udl file in a text editor - It will contain the connection string that was used for the successful connection
Now you can compare the connection strings / use the one you now that works...
Good luck!
Try this code
Data Source=xx.xx.xxx.xx;Initial Catalog=KnightOwl-Demo;Persist Security Info=True;

SQL Server Express connection string error

Trying to figure out the correct connection string for a SQL Server Express database. Trying to publish my app to IIS and test before publishing to my hosting site.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I started here and also used connectionstrings.com. I also started reading the deploy asp.net app using SQL Server Compact article here
Using this connection string
Data Source=.\\SQLExpress;AttachDbFilename=H:\DB\Guestbook.sdf;Integrated Security=True
I get the above error
This connection string
<add name="DefaultConnection"
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI; database=Guestbook; AttachDBFilename=|DataDirectory|Guestbook.sdf"
providerName="System.Data.SqlClient" />`
throws a trust level error. I've changed to medium and full and still get one of the two errors.
I've tried a variation of a few different strings with no luck.
Thanks
Please verify that SQL Service is started in services.msc and use the complete instance with the hostname ej: HOSTNAME\SQLEXPRESS
The file extension indicates that this is not a SQL Server Express database, so you must use:
Data Source=<Full path to file>
or
Data Source=|DataDirectory|Guestbook.sdf

How to connect to SQL Server 2000 from .net 4

Here's my connection string...
Data Source=MYMACHINE\SERVER2000; Initial Catalog=MyDatabase; User Id=sa; Password=p;
Here's the error....
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
I can connect fine with Enterprise Manager. Also I have upgraded the SQL Server to Serivce Pack 4.
Any ideas what the issue might be?
I'd suggest testing your connection string using a .UDL file. I've answered a similar question here. After creating your connection, you can rename the extension of the file to .txt, open it and then copy and paste the working connection string in.
string connectionString=#"Data Source=MYMACHINE\SERVER2000; Initial Catalog=MyDatabase; User Id=sa; Password=p;";
SqlConnection connection=new SqlConnection(connectionString);
SqlCommand command = new SqlCommand("Select * From Table",connection);
SqlDataReader reader= command.ExecuteReader();
GridView1.DataSource=reader;
GridView1.DataBind();
Use this.... this may help you?

Cannot connect to local instance of SQL Server database using Entity Framework Code First - error: 26 - Error Locating Server/Instance Specified

I have an MVC web application using EF 5.0 (Code first) that connects to a local database (on the same server) using this connection string:
"Data Source={server}\{instance};Database={database};user id=sa;password={password}"
The database is dropped and re-created when the DbContext is first initialised. After that it throws the following exception:
System.Data.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. ---> System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I've hosted another application on the same server, using exactly the same connection string to access the database using a SqlConnection object in old-school ADO.Net fashion which connects fine.
I've checked for similar posts and all suggest a number of things which I have tried but have not solved the problem:
Add TCP/IP aliases for server instances
Check firewall allows inbound connectivity via TCP:1433 and UDP:1434 ports
Check that SQL Server Browser is running on the server
Check that the connection string is valid and that the specified user has access to the SQL Server instance
Just to add a odd twist to the whole thing: I can connect to the same database on the same server from my workstation running IIS Express but as soon as it's hosted on the server I get the above problem.

Best practise while using 'SQlDataAdapter'

There is common function I am using in my project for returning dataset. I am using a 'SQLDataAdapter' here. This works fine for 3 other projects. But in one of the projects, this function threw an error when run from one of the client machines. (Works fine on server machine).
Error:-
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Here is the source code of the function:-
Public Function Fn_Return_Dataset(ByVal sqlquerys As String) As DataSet
' This function is used to return a dataset for given query
If mydb.State <> ConnectionState.Closed Then
mydb.Close()
End If
Dim dap As New SqlDataAdapter(sqlquerys, mydb)
mydataset = New DataSet()
Try
dap.Fill(mydataset)
Catch Exdat As Exception
writelog(Exdat.Message.ToString, "MYDATA", "FN_RETURN_DATASET")
showmsg("Sorry.....Unable to return dataset")
Finally
If mydb.State <> ConnectionState.Open Then
mydb.Open()
End If
End Try
Return (mydataset)
End Function
If your code works fine on server machine and not on client machine then you have communication problem. Check if your SQL engine has TCP enabled and if firewall is opened. You may have some DNS related/name resolution related problem - check server name in connection string - do simple ping with server name to check if client machine can resolve server name to IP.

Resources