Asp.net error on trying to connect with database - c#

I am trying to connect to a database which is an .mdb file from my web application on asp.net. This error comes up 'Microsoft.ACE.OLEDB.12.0 Data Source =C:\Users\KIKI\Desktop\ASP.net labs\Erg8\Erg8\ebookstoredb.mdb' provider is not registered on the local machine. The thing is that on my connection string I don't use version 12 but 4. I tried installing Microsoft Access Database Engine 2010 Redistributable which gives me the option to select version 12 when I set it the connection from the "Server Explorer" window but the error is still there. Any ideas? I have spent hours looking for a solution...
Here is my connection string:
OleDbConnection constring = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\KIKI\\Desktop\\ASP.net labs\\Erg8\\Erg8\\ebookstoredb.mdb");
Also, I tested the connection when I set it and a message "Connection Succeeded" came up. The problem seems to be when I run the application on the browser.

Related

I can't connect to a local SQL Server instance via Entity Framework using Windows authentication

I can't connect to my local SQL Server Express instance via Entity Framework. When I try to run the update-database command, I get this error message.
Login failed for user ''. Reason: An attempt to login using SQL authentication failed.
Server is configured for Integrated authentication only.
Error: 18456, Severity: 14, State: 58.
From what I understand, Visual Studio is attempting to log in to SQL Server via a user account even though I've requested that Windows authentication is used in the connection string.
I can still access the server via SSMS.
What I've tried. None of which helped
Different variations of the connection string
Opened port 1433
Created a test UDL file to test the connection.
A clean reinstall of SQL Server Express (not sure I managed to clean up all the files)
Checked the SQL Server browser is running
Checked server instance is running
Enabled TCP/IP & named pipes
Tried connecting via tcp which works
Added Integrated Security=SSPI to connection string
Changed server to accept Windows authentication and SQL Server authentication.
Restarting PC
This is a new laptop on windows 11, I don't know if that is causing any issues as I've never had an issue with this process on Windows 10.
I seem to have two instances; .\SQLEXPRESS & (localdb)\\MSSQLLocalDB I'm not sure if this is causing some conflict or if this is the intended behaviour.
Here is the connection string, I pulled this from the server explorer within Visual Studio so I am pretty sure this is correct. On top of that, I have tried numerous variations of this to attempt to fix the issue
"DefaultConnection": "Data Source=LAPTOP-51LB4QTQ\\SQLEXPRESS;Initial Catalog=MicroBlog;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
This is where I get the connection string in my Program.cs file
builder.Services.AddDbContext<BlogContext>(opt => opt.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
var app = builder.Build();
At this point I'm completely lost, I've read a lot of articles but have not come across any fixes. I'm not a dba just a programmer so have limited knowledge of this side of SQL Server.
You may try like below:
In Web.config file:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=SUBRATATALUKDER;Initial Catalog=MyDB;Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
In appsettings.json file:
"ConnectionStrings": {
"DefaultConnection": "Server=SUBRATATALUKDER;Database=MyDB;Trusted_Connection=True;TrustServerCertificate=True;",
}
Note:
Server Name = SUBRATATALUKDER
Database Name = MyDB
100% tested.

SQL Server network interfaces error 52- Unable to locate a database at runtime installation

I am creating a POS system in Windows Forms (C#) in which I use a SQL Server database file (.mdf) to store items (completely offline). When I install the application on my computer, it works fine, but when I install it on my clients PC, an error happens:
(provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation"
I read somewhere that the problem is caused due to the fact that the connection string of the database of my client's PC is different. I tried to add the connection string dynamically on runtime but again it only worked on my computer.
Another reason that might be causing the problem is that I used 'server-based database' since local database option isn't available in Visual Studio 2017 for some reason.
Another solution I looked up stated that I should install SQL Server Express on my client's PC. That also failed (maybe I have to set it up in a way or something).
I also tried adding the database.mdf and database_log files in the setup folder.
Lastly I tried installing 3rd party installers (Advanced installers 15.8 and InstallShield Wizard in VS 2015) which also failed.
(I have provided the code for the connection of database taking place and the connection string)
public void ConnectToDB()
{
DBConnection = new SqlConnection(#"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=C:\Users\SAIM NASSER\Desktop\app layer\data layer\Database1.mdf; Integrated Security = True");
DBConnection.Open();
ResultSet = new DataSet();
}
If I understand you correct, you want to use LocalDB
That means using Sql Server without installing a full sql server, but just the localdb part from sql server express.
For this to work you need to install the LocalDB Driver, which can be found here
https://www.microsoft.com/en-us/download/details.aspx?id=29062
You need only the ENU\x64\SqlLocalDB.MSI
This is the only thing you need to install in your clients computer, I believe it can also be installed silent, you have to research a bit for that.
And yes, you also should change the connection string on the clients computer, you need to alter it so it points to the MDF file on the clients computer, because that location will probably be different then on your computer
EDIT
To get the connection string working, you can try this
On the clients computer, create a text file and rename the extension to .udl
So for example you have a file test.udl
Now from explorer, double click it, this will open the datalink editor.
From here you can enter/choose different settings, and click on the test connection button.
Once you get a working connection, save it, and open this file with notepad.
Inside you will find the working connection string
Hope this helps

Connecting to an mdb file using OdbcConnection in VS2013

I am trying to connect to an mdb file from C# 2013 using OdbcConnection. I used to have Office 2000 on my Windows 7 and Windows 8 machines, but I have upgraded to Office 2013 on both and it now longer works on either. My database is still in mdb format.
Here's the code:
const string myConnectionString = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Path\Mydb.mdb";
OdbcConnection connRL = new OdbcConnection();
connRL.Open();
Whatever I have tried I get the following error:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not
found and no default driver specified
I have Installed the "Microsoft Access Database Engine 2010 Redistributable" and the "2007 Office System Driver: Data Connectivity Components" but neither of them have made any difference. I can create a new Data Source from the VS 2013 Project menu and that all works at design time.
When I create a blank udl file and double click on it and go to the provider tab there's nothing listed about Access or Jet, but I can see the providers in the registry at HKEY_CURRENT_USER\Software\Microsoft\VWDExpress\12.0_Config\DataProviders. Why aren't they there?
What else can I do to get this to work? I have tried everything I can think of.
I assume you can't connect to the mdb through OdbcConnection. Anyway, to connect to the DB you must specify the connection string on your connection object which is not specified in your code.
To access mdb use code like this:
const string myConnectionString = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Path\Mydb.mdb";
using(var connRL = new OleDbConnection(myConnectionString))
{
//use your connection
}

Visual Studio 2013 DB creation error : a network related or instance specific error occurred while establishing connection with sqlserver

First of all, let me tell you that I have tried every damn thing by Googling to overcome this error and I have not done any TYPO error either. But, none of the Google results helped. Let me tell you the scenario... I installed Visual Studio Ultimate 2013 (and nothing else, no separate sqlexpress, nothing). All non-DB apps are working fine. But, for one project, when I tried to create new database connection (by right clicking 'data connections' or clicking 'connect to database' icon for creating localdb), I got this 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:
sqlnetwork interfaces, error 26- Error locating server/Instance
specified)"
Then, as usual, I tried to Google for it. But most of the answers were related to sqlexpress (which I didn't installed separately). Then one answer was about "sqlserver configuration manager" and enabling sqlservices and something called surface area.... But, as "sqlserver configuration manager" was not there in my 'all programs' on my windows 8 (64x) machine, I downloaded sqlexpress and sqlserver management studio too. But an item named something like "surface area manager...." was not there. I enabled sqlservices, all tcp/ip ports. Shut down my firewall. Still getting the same error.
NOTE: I dont have any connection string in my webconfig till now because I was just going to create the new DB. So the the answer about editing conn string doesn't mattered to me.
NOTE: This was not the case with Visual Studio 2012. On only VS2012 (and nothing else) installation, it worked fine for creating the DBs and all other things. So, what's wrong with VS2013??
Server \ Instance name must be reachable from your client, as the creation of the connection string will try to verify that it connected OK. Try this from your workstation:
sqlcmd -Sservername\Instance_or_IPaddress_of_Sql_server -E -Q"select ##version"
Until you get a proper server name or instance, you will not be able to successfully create a db connection.

SqlException: Server does not exist or connection refused

I am using c# on monodevelop on Ubuntu x64.
I am trying to use Mono.Data.Sqlite to connect to a local (localhost) database but I cant connect to it.
This is my connection string:
string connsqlstring = "Server=localhost;" +
"Database=wsep;" + "User ID=root;" + "Password=1234;" + "Pooling=false";
But I keep getting:
System.Data.SqlClient.SqlException: Server does not exist or connection refused.
I have started the server (sudo /etc/init.d/mysql start)
What am I missing?
Simply put, SQLite isn't the same thing as MySQL. They're different databases.
SQLite is a flat file database, the mono side of which you can read about here.
MySQL has information on the mono website and that page also provides links to downloading the MySQL connector for use with your mono projects. You will want to look at these links for working with MySQL.

Categories

Resources