I am trying to run an application that has been downloaded from GitHub. The creator of the project provided usernames and passwords to log in for the application. Whenever I try to log in, I get an error that says:
"System.Data.SqlClient.SqlException: 'Cannot open database "Library" requested by the login. The login failed.
Login failed for user 'DESKTOP-CBKOJI6\user'."
I tried doing the following but I still keep getting the same error
Cannot open database "test" requested by the login. The login failed. Login failed for user 'xyz\ASPNET'
<connectionStrings>
name="DbConnection"
connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Library;Integrated Security=TrueConnect; Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />
</connectionStrings>
This is the database that is in the App.config
The error I get is in this line of code:
con.Open();
EDIT 1:
Link for the project >> https://github.com/RuXeR97/Library
You have to actually create the database first... You can't log into it if it doesn't exist.
Did the download come with a database project (you can publish that through visual studio), or .sql files (you can run them in SQL Server Management Studio) to create the database first.
Maybe link to the github project so we can take a look?
Data Source=(localdb)\MSSQLLocalDB;
According to this line of code, you are trying to log into a local database which is supposed to be created by yourself locally. If the Github author already created a database on server and provided you with credentials, then all you have to do is to update this localDB server by the server name he provided in Github page.
i am beginner is programming. I want to write a program by c# in visual studio 2015 with a simple database that takes some data, save it and read from that database.
I wrote some of my code in a windows form application and now I want to add a database. I right-click on on my project name in the solution explorer and then choose "Add" and the "New Item". In the the opened window i click on "Service-Based Database", enter name and click on Add button.
But at this moment it show me an error that u can see below:
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 names is correct and that SQL Server is configured to allow remote connections. (Provide: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I did this before it and there was no error, but now I see to this error and I don't know what's the problem.
I have installed SQL server 2015 on my windows 10 and when I enter "sqllocaldb.exe i" in the cmd, it shows me:
dbname
MSSQLLocalDB
how can i solve this problem and add new database to my applications?
I have installed sql server on my computer and repair it once but when i wanted to check it from windows services i couldn't find sql server in the servisec.
thank you for your attention
Go to your SQL Configuration Manager,
then on left panel click on Sql Server Services (highlighted),
might be that your SQL Server Default Instance (MSSQLServer) or whatever instance name you gave it, it's state might not be running. so start it up. Then try it again.
I have Visual Studio 2015 installed and I created a sample application from some Microsoft tutorial.
This is the connection string I got in web.config:
<add name="DefaultConnection"
connectionString="Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-GeekQuiz-20160203041206.mdf;Initial Catalog=aspnet-GeekQuiz-20160203041206;Integrated Security=True"
providerName="System.Data.SqlClient" />
But it doesn't work, this is the error I got:
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.
Should I install SQL Server Express separately or I got it along with Visual Studio?
I usually use the next trick to set the correct connectionString in the Web.config:
In Visual Studio, go to the “SQL Server Object Explorer” label, right-click on the Database you wish to use and click on “Properties”. Then get the string in the “Connection string” field.
Try giving permissions to SQL server on the directory of App_Data. Go to properties->Security->Edit->Add and add the sql server instance name. It is usually NT Service\MSSQL$InstanceName. You can find instance name from sql server configuration manager-> Under SQL Server Network Configuration. If this doesn't help, then try adding PC Name\Users. It should work after that
I am trying to build an ASP.NET MVC 5 Web Application which has a MyDatabase.mdf file in the App_Data folder. I have SQL Server 2014 Express installed with a LocalDb instance. I can edit the database tables using the Server Explorer, however when I debug the application and go to a page where the database is needed I get 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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
So I looked in the Event Viewer under Application and only see one Warning over and over again.
The directory specified for caching compressed content C:\Users\User1\AppData\Local\Temp\iisexpress\IIS Temporary Compressed Files\Clr4IntegratedAppPool is invalid. Static compression is being disabled.
So I tried rebooting the server, still no go. Same error 50 as before.
I have created an class under Models where I have a class called Post.
namespace MyApplication.Models
{
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}
public class MyDatabase : DbContext
{
public DbSet<Post> Posts { get; set; }
}
}
I also have a Controller setup to list the posts from MyDatabase.
namespace MyApplication.Controllers
{
public class PostsController : Controller
{
private MyDatabase db = new MyDatabase();
// GET: Posts
public ActionResult Index()
{
return View(db.Posts.ToList());
}
}
In my web.config file the connection string looks like this...
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDB)\v12.0;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I've tried the suggestion posted here but it didn't work. Also tried this.
I also notice that the MyDatabase instance gets disconnected after I start running the application. If I refresh the database using Server Explorer in Visual Studio I can view the tables.
How is it that I can connect to the database and edit it within Visual Studio 2013 but when I debug the application it cannot connect to the database?
Breaking Changes to LocalDB: Applies to SQL 2014; take a look over this article and try to use (localdb)\mssqllocaldb as server name to connect to the LocalDB automatic instance, for example:
<connectionStrings>
<add name="ProductsContext" connectionString="Data Source=(localdb)\mssqllocaldb;
...
The article also mentions the use of 2012 SSMS to connect to the 2014 LocalDB. Which leads me to believe that you might have multiple versions of SQL installed - which leads me to point out this SO answer that suggests changing the default name of your LocalDB "instance" to avoid other version mismatch issues that might arise going forward; mentioned not as source of issue, but to raise awareness of potential clashes that multiple SQL version installed on a single dev machine might lead to ... and something to get in the habit of in order to avoid some.
Another thing worth mentioning - if you've gotten your instance in an unusable state due to tinkering with it to try and fix this problem, then it might be worth starting over - uninstall, reinstall - then try using the mssqllocaldb value instead of v12.0 and see if that corrects your issue.
Running this:
sqllocaldb create "v12.0"
From cmd prompt solved this for me...
I usually fix this errore following this msdn blog post Using LocalDB with Full IIS
This requires editing applicationHost.config file which is usually located in C:\Windows\System32\inetsrv\config. Following the instructions from KB 2547655 we should enable both flags for Application Pool ASP.NET v4.0, like this:
<add name="ASP.NET v4.0" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
To begin - there are 4 issues that could be causing the common LocalDb SqlExpress Sql Server connectivity errors SQL Network Interfaces, error: 50 - Local Database Runtime error occurred, before you begin you need to rename the v11 or v12 to (localdb)\mssqllocaldb
Possible Issues
You don't have the services running
You don't have the firelwall ports here
configured
Your install has and issue/corrupt (the steps below help give you a nice clean start)
You did not rename the V11 or 12 to mssqllocaldb
\\ rename the conn string from v12.0 to MSSQLLocalDB -like so->
`<connectionStrings>
<add name="ProductsContext" connectionString="Data Source= (localdb)\mssqllocaldb;
...`
I found that the simplest is to do the below - I have attached the pics and steps for help.
First verify which instance you have installed, you can do this by checking the registry& by running cmd
1. `cmd> Sqllocaldb.exe i`
2. `cmd> Sqllocaldb.exe s "whicheverVersionYouWantFromListBefore"`
if this step fails, you can delete with option `d` cmd> Sqllocaldb.exe d "someDb"
3. `cmd> Sqllocaldb.exe c "createSomeNewDbIfyouWantDb"`
4. `cmd> Sqllocaldb.exe start "createSomeNewDbIfyouWantDb"`
ADVANCED Trouble Shooting Registry configurations
Edit 1, from requests & comments: Here are the Registry path for all versions, in a generic format to track down the registry
Paths
// SQL SERVER RECENT VERSIONS
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\(instance-name)
// OLD SQL SERVER
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSSQLServer
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer
// SQL SERVER 6.0 and above.
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MSDTC
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SQLExecutive
// SQL SERVER 7.0 and above
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SQLServerAgent
HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server 7
HKEY_LOCAL_MACHINE\Software\Microsoft\MSSQLServ65
Searching
SELECT registry_key, value_name, value_data
FROM sys.dm_server_registry
WHERE registry_key LIKE N'%SQLAgent%';
or Run this in SSMS Sql Management Studio, it will give a full list of all installs you have on the server
DECLARE #SQL VARCHAR(MAX)
SET #SQL = 'DECLARE #returnValue NVARCHAR(100)'
SELECT #SQL = #SQL + CHAR(13) + 'EXEC master.dbo.xp_regread
#rootkey = N''HKEY_LOCAL_MACHINE'',
#key = N''SOFTWARE\Microsoft\Microsoft SQL Server\' + RegPath + '\MSSQLServer'',
#value_name = N''DefaultData'',
#value = #returnValue OUTPUT;
UPDATE #tempInstanceNames SET DefaultDataPath = #returnValue WHERE RegPath = ''' + RegPath + '''' + CHAR(13) FROM #tempInstanceNames
-- now, with these results, you can search the reg for the values inside reg
EXEC (#SQL)
SELECT InstanceName, RegPath, DefaultDataPath
FROM #tempInstanceNames
Trouble Shooting Network configurations
SELECT registry_key, value_name, value_data
FROM sys.dm_server_registry
WHERE registry_key LIKE N'%SuperSocketNetLib%';
An instance might be corrupted or not updated properly.
Try these Commands:
C:\>sqllocaldb stop MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" stopped.
C:\>sqllocaldb delete MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" deleted.
C:\>sqllocaldb create MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" created with version 13.0.1601.5.
C:\>sqllocaldb start MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" started.
maybe this error came because this version of Sql Server is not installed
connectionString="Data Source=(LocalDB)\v12.0;....
and you don't have to install it
the fastest fix is to change it to any installed version you have
in my case I change it from v12.0 to MSSQLLocalDB
Final Solution for this problem is below :
First make changes in applicationHost config file. replace below string setProfileEnvironment="false" TO setProfileEnvironment="true"
In your database connection string add below attribute : Integrated Security = SSPI
I ran into the same problem. My fix was changing
<parameter value="v12.0" />
to
<parameter value="mssqllocaldb" />
into the "app.config" file.
All PLEASE note what Tyler said
Note that if you want to edit this file make sure you use a 64 bit text editor like notepad. If you use a 32 bit one like Notepad++ it will automatically edit a different copy of the file in SysWOW64 instead. Hours of my life I won't get back
In my case, we had several projects in one solution and had selected a different start project than in the package manager console when running the "Update-Database" Command with Code-First Migrations.
Make sure to select the proper start project.
I have solved above problem Applying below steps
And after you made thses changes, do following changes in your web.config
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v12.0;AttachDbFilename=|DataDirectory|\aspnet-Real-Time-Commenting-20170927122714.mdf;Initial Catalog=aspnet-Real-Time-Commenting-20170927122714;Integrated Security=true" providerName="System.Data.SqlClient" />
My issue was that i had multiple versions of MS SQL express installed. I went to installation folder C:\Program Files\Microsoft SQL Server where i found
3 versions of it. I deleted 2 folders, and left only MSSQL13.SQLEXPRESS which solved the problem.
A friend of mine setup a Jenkins build server with automatic deployment to Azure. The website used to work fine after deployment, but after we branched our solution and then merged it again (after changing from .aspx to razor) the website displays the following error (locally everything works fine):
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)
Unfortunately we (the two that are left behind) cannot ask our friend how to solve this since he is on a vacation.
After searching on the internet we think it has something to do with our connection string that might be changed. Locally we can connect to the remote Azure database via the "Connect to Database" option in the Visual Studio Server Explorer. When we right click this connection and copy the connection string into our web.config and/or publish profile we still get the same error message on the website.
Our connection string in the web.config looks like this:
<add name="DefaultConnection" connectionString="Data
Source=*******.database.windows.net;Initial Catalog=blablaAszH;Persist
Security Info=True;User ID=testserver#blabla;Password=ourpassword"
providerName="System.Data.SqlClient" />
I do not know what other relevant information I can post but if you ask for it I will place it here.
(The main goal is actually just to deploy the website. But we cannot do this via Visual Studio since only our friend knows the username and password and he's disconnected from the world. These are not the same as in the connection string since when we publish from Visual Studio it says the web deployment task failed because of a wrong username and password. So we need to publish via committing our project to SVN and Jenkins doing the deployment.)
Does anyone here know how to solve this issue or with what it might be related?