I want connect to SQL Server Compact 4.0 in my ASP.NET application.
Here is example of code:
protected void Page_Load(object sender, EventArgs e)
{
string connStr = "Data Source=D:\\MyDB.sdf;";
string sqlStr = "select * from tblMyTable";
var sqlDataSrc = new SqlDataSource(connStr, sqlStr);
GridWithUrls.DataSource = sqlDataSrc;
GridWithUrls.DataBind();
}
But I have the next 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)"
The SqlDataSource has constructor with three parameters, one of them is 'providerName' so, how to specify that I want definitely use Sql Server Compact provider ? Also I have added System.Data.SqlServerCe reference..
ASP.NET Database Connection can connect with most databases, including Oracle, Microsoft SQL Server, MongoDB, and MySQL. Here we are going to use Microsoft SQL Server as our database. Microsoft SQL Server is free database software, and one can easily download and install Microsoft SQL Server Express Edition.
Select >new Project from web option use ASP.NET empty Web Application. After loading project, select click Tools at top then select connect to Database option. Add connection dialogue box will appear click at change option and select the Microsoft SQL Server. Now enter your server name.
Right-click Data Connections, and then click Add connection. In the Data Link Properties dialog box, click localhost in the Select or enter a server name box. Click Windows NT Integrated Security to log on to the server. Click Select the database on the server, and then select Northwind database from the list.
Try:
providerName = "System.Data.SqlServerCe.4.0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With