SQL Server Compact Database File - visual-studio

I have a SQL Server Compact Database file (.sdf) that I am trying to connect through using Visual Studio 2017. I have installed SQLight / SQL Server Compact ToolBox with NuGetPackage Manager.
I have placed a SqlDataSource on the ASPX page.
I click new "Connection" Select "SQL Server Compact 4.0 (Simple by ErikEJ)"
Put in the Data Source.
Test Connection "Test connection succeeded".
Click OK and I get this error
Exception of type 'Microsoft.VisualStudio.Web.Data.InternalException' was thrown
I have searched google can not find anything about this. I can connect to different SQL Server databases but not to this .sdf.
Any recommendations?

SqlDataSource does not work with SQL Server Compact (or vice versa). Use for example EF Core or ADO.NET for data access instead.

Related

SQL Server 2017 Connections working in ASP.NET C# Web projects, but not in Windows projects, in Visual Studio 2019

Using the basic SqlConnection code below, I have discovered that, at my workstation, I am unable to connect to our Sql Server 2017 deployment via ASP.NET C# code in any given type of Windows-based project, such as Winforms (.NET Framework or Core) or Console apps. However, this code will run without incident in any Web-based project, such as Web Forms or MVC, either using .NET Framework or Core.
protected void testConnection()
{
string con = "Server=MySqlServer;database=MyDatabase;Integrated Security=true";
using (SqlConnection cnn = new SqlConnection(con))
{
cnn.Open();
cnn.Close();
}
}
In a web project, this code runs. In a Windows project, I get this error:
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
In investigating this problem, I have tried the following:
Explicitly declaring the domain on which my SQL server is found (eg. MySqlServer.domain.com). No good.
Explicitly declaring the SQL Server port number, according to the example shown on connectionstrings.com (eg. MySqlServer, 1433). We do use the standard port number, for the record. No good.
Changing the protection level of the test method (protected/private/public). No good.
Connecting to the SQL Server in PowerShell. This connection worked.
Pinging in the SQL Server in a command prompt. The server responded in 1ms consistently.
I have asked other users on this network to test this code in a Winforms project on their workstations. No one is able to reproduce my issue.
Consulted my sysadmin. He is so far not able to find any reason why I should be having this issue.
The only difference I have noticed in all of this is that, when I declare the port number, the Inner Exception returned with the error reads "Win32Exception: A non-recoverable error occurred during a database lookup". Otherwise, it simply reads "Access is Denied."
All of this tells me that the issue is obviously something peculiar to my workstation, but I have no idea what, apart from some firewall or other local security setting that the sysadmin neglected to check. Has anyone encountered this problem?
My VS 2019 installation is only one revision out of date as of this writing, 16.8.3 as opposed to 16.8.4. I am able to connect to and run TSQL code on any database I care to via SSMS. We connect using Windows Authentication. According to the results of "select ##version", our version of SQL Server is 2017, 14.0.3356.20 (x64).
Any insight is appreciated.
We fixed it by forcing Named Pipes to be enabled in SQL Server, as opposed to using the default setting.

Can't access Azure SQL database with Visual Studio but can with SSMS

I'm trying to connect to an SQL database hosted on Azure from a function app I'm building in Visual Studio but I'm getting the following 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: TCP
Provider, error: 0 - An attempt was made to access a socket in a way
forbidden by its access permissions.)
I can connect from the same PC using SSMS without a problem. I've tried connecting to the database using data connections in server explorer in VS but I'm getting the same error. If I connect to Azure with my account in server explorer it shows me a selection of services including SQL databases but there are none listed underneath although my account does have access to the database.
Are there any hidden gotchas I'm missing or settings within VS? I've also tried adding my client IP in the firewall settings but that didn't make a difference either.
After doing some more testing it turned out to be the client firewall that was blocking VS and VS Code from connecting to Azure SQL. It seems there was already an exception for SSMS.
The error message states "Verify that the instance name is correct"
It could be that the SSMS is automatically creating a fully qualified name once you say that it is an azure database.
If you use the short name from Visual Studio, then you cannot connect to the SQL server.
For example "myserver.database.windows.net" versus "myserver".

Entity Data Model Wizard can't find my Connection

In VS 2019, I created a connection in Server Explorer. The connection is for Oracle and it passed the Test and was created successfully. However, when I go to create an ADO.NET Entity Data Model, on the screen which asks "Which data connection should your application use to connect to the database?" and has a combo box immediately below that question, there are no connections from which to choose. Why doesn't my connection show up there? I even restarted Visual Studio with no difference.

EF 4.1 / SQL Server CE 4.0 without local SQL Server Express

I have an MVC3 project that uses EF 4.1 database first with a SQL Server CE database. On my dev box, which has SQL Server Express installed, everything works fine. However, when deploying to another server that does not have SQL Server Express installed (or any SQL Server Instance), the connection understandably fails. Is it possible to use EF 4.1 with a SQL Server CE database on a box that does not have a local SQL Server instance?
Even if I try to reference a remote SQL instance, I receive an error
Invalid value for key 'attachdbfilename'
Here is what the connection string looks like:
<add name="AlertsEntities" connectionString="metadata=res://*/Models.AlertsModel.csdl|res://*/Models.AlertsModel.ssdl|res://*/Models.AlertsModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\Alerts.mdf;integrated security=True;connect timeout=30;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I actually blogged about just that a little while back. http://enterpriseyness.com/2011/11/deploying-an-asp-net-web-application-with-sql-ce-4-entity-framework-without-installation/
If you rlight click on the web project, you'll see an 'Add Deployable Dependencies' menu item. Also, don't forget to add the SQL CE provider factory to your Web.config.
Just to update how we solved this problem, we ended up just installing SQL express on the same server as the application using SqlCE. I'm accepting this answer just because the other one didn't really answer the question at all.

Opening SQL Server Express via JDBC in Mathematica?

I have two computers with two (ostensibly) identical installations of SQL Server Express 2008 R2, both running Windows 7 64-bit. On one computer (call it "red"), I can execute the following mathematica code to open a connection to the database and read data
Needs["DatabaseLink`"]
conn = OpenSQLConnection[
JDBC[
"Microsoft SQL Server(jTDS)",
"localhost"],
"Instance" -> "SQLExpress"]
I have the jTDS driver for sql server installed in c:\windows\system32\ntlmauth.dll. I copied the dll from the working machine "red" to the non-working machine "black."
I used the SQL-Server import and export tool to transfer a very simple database from "red" to "black" and verified that the database is accessible by running LinqPad on "black" and reading data. All good.
Now, I try to run the Mathematica code above on "black" and I get an undiagnosable error message, namely:
JDBC::error: "!(TraditionalForm`\"Network error IOException: Connection refused: connect\") "
I just know this is going to be one of those nightmarish permission issues with the localservice account or the network-service account. I do not have Sql-Server Management Studio on machine "black" and I was unable to find the appropriate version of SSMS to install for SQL Server 2008 R2 Express (the SSMS Express 2008 version does not install, citing "known compatibility issues.") I don't really miss SSMS since LinqPad works fine for my development tasks.
I do not know how to diagnose or workaround or proceed in any way -- I'm completely blocked and would be very grateful for advice or guidance.
Somewhat guessing here, but I'd try
conn = OpenSQLConnection[
JDBC[
"Microsoft SQL Server(jTDS)",
"localhost:1433;instance=SQLExpress"]]
I'm pretty sure OpenSQLConnection[] doesn't take an "Instance" option. It might work if passed like this:
conn = OpenSQLConnection[
JDBC[
"Microsoft SQL Server(jTDS)",
"localhost:1433"], "Properties"->{"instance"->"SQLExpress"}]
Connection Error while connecting to SQL Server. It is not an authentication error.
It is just that may be your SQL Server is not configured to accept request through
through the transport protocol that you are using. Open SQL Server Surface Configuration
Manager and allow to accept connection from all ways provided.

Resources