I reinstaled my PC and now I have problems with my SQL connection string or with SQL Server 2012 Enterprise
Error I get:
"... (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)" or
"... (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
In SQL Server Management Studio server instance looks like this:
TOM-PC (SQL Server 11.0.3128 - Tom-PC\Tom)
And My SQL connection string in ASP.NET XML config. file:
<add name="ApplicationServices" connectionString="Data Source=.\TOM-PC;Database=D:\Programming\InvoiceManager\invocemanagerSQL.mdf;" providerName="System.Data.SqlClient" />
Tried everything, in firewall added port 1434 or 1433 tested both, not working, "SQL Server Browser" Service is running, TCP/IP Enabled, Allow remote connections to this server, even tried 4 different connection strings, nothing worked.
Before it worked like a charm, not fully but worked. Why not fully? Because I couldn't work on my local machine with both studios "VS2010" and "SQL Management studio" at the same time, if I needed change something in database manually, I needed to stop or restart SQL Server process and service, then I get in database, and read tables. Now, nothing is working!
What I do or did wrong? Where seems to be the problem? Why always are problems with SQL servers and it's connectionstrings?
What you are seeing in Management Studio is as follows:
Instance Name (SQL Server version - Domain\LoggedInUser)
You are logged in using integrated authentication (i.e. your windows logon account) but not specifying it in the connection string. This will try to use the currently logged on user for the ASP.Net application, which will almost certainly not be running as your windows account. It will either be one of the local or network service accounts or a built-in ASP.Net user.
You're also using the wrong variable name to attach the database file, if this is actually what you want rather than connecting to an actual database on the server.
What I suggest you do is enable SQL Server authentication on your instance, create a new user and give it permissions to the database as required.
You would then log in using the following format:
Server=myServerAddress; Database=myDataBase; User Id=myUsername; Password=myPassword;
Where myServerAddress would be localhost or TOM-PC; Database would be the name of the database as it appears in Management Studio; User Id would be the username for the user you just created and Password would be the password you set for them during creation.
If you do actually want to attach a database file then your connection string changes to use this format:
Server=myServerAddress; AttachDbFilename=C:\Path\To\Database\File.mdf; Database=myDataBase; Trusted_Connection=Yes;
Typically, you can get most connection string variants that you will need from: http://www.connectionstrings.com/sql-server/
Related
Installed SQL Server Express 2014 & can connect/query with SSMS. I'm using Visual Studio 2015 (C#) and EF 6 to programatically connect to the server. In all the following scenarios I'm using the same connection string + am using the "sa" account with the correct password in the connection string.
When I sign in to the computer with a Windows domain account (ex: domain\username) then run the code it works fine.
When I sign in to the computer using a local account (ex: computername\username) account then run the code it fails with the following error: The underlying provider failed on Open. Note that I can launch and use SSMS w/out problems.
Here's my connection string.
metadata=res://*/[efName].csdl|res://*/[efName].ssdl|res://*/[efName].msl;provider=System.Data.SqlClient;provider connection string=\'Data Source=.\SQLExpress;Initial Catalog=db-name;Integrated Security=True;User ID=sa;Password=[psw];MultipleActiveResultSets=True;Application Name=EntityFramework;User Instance=False\'
I've tried with Integrated Security on or off (same result). Tried Data Source as ".\SQLExpress" or "[machineName]\SQLExpress" (same result).
After digging a bit I found the following entry in the Windows Event Viewer.
Level: Information
Source: MSQL$SQLEXPRESS
Task Category: Logon
Message: Login failed for user 'computername\username'. Reason: Failed to open the explicitly specified database 'db-name'. [CLIENT: ]
Looks to me like SQL Server windows service is using some kind of network auth prior to allowing a connection to SQL Server.
It's probably no surprise that the error message returned by EF/SQL didn't help at all. It has nothing to do with the underlying provider...
After some trial/error I've whittled it down to this. It's required that you set IntegratedSecurity=false when providing specific userName/Password credentials in the connection string. That's it.
I am developing a program with C# and WPF. I want the data to be stored in an SQL Server database. I made a connection string with the instance name in my PC, and that worked. But when I want to connect through the Internet with an IP address, I get some errors:
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. (TCP Provider,
error 0 - No connection could be made because the target machine
actively refused it.)
I enabled TCP/IP, allowed remote connection in SQL Configuration Manager, opened a port of 1433 in my firewall, but still I am getting this error.
My connection string is this:
String connString = #"Network Library=dbmssocn;
Network Address=127.0.0.1,1433;
Integrated security=SSPI;
Initial Catalog=db";
SqlConnection conn = new SqlConnection(connString);
conn.Open( );
Where is my mistake?
There is very slight error in your connection string and honestly I can't blame you for that as it is very weird way in which SQL Sever is behaving. I'm not sure if this error lies in connection provider side or SQL Server instance side. Name of Network Library that your application is using to connect to the SQL Server using dbmssocn(Win32 Winsock TCP/IP) should always be mentioned in capital letters. Though I didn't see any relevant MSDN documentation from MS to support my statement but it actually worked when I did so. Here is the connection string that you should be using to fix the error.
String connString = #"Network Library=DBMSSOCN;
Network Address=127.0.0.1,1433;
Integrated security=SSPI;
Initial Catalog=db";
Seriously, I got freaked out in reproducing your issue as instead of copying the connection string from your question I copied it from some other blog :). But all is well that ends well. I've also assumed that a database named "db" actually exists on the default (NOT named instance) instance of the sql server you are connecting to when typing this answer. If changing the casing of network library name in connection string doesn't help then double check that database "db" must exist for a sql server default instance to which you are connecting to. In case you are using a named instance of sql server in your installation then that instance name should also come in the connection string.
Configure your SQL Server to allow TCP/IP connections. Go to SQL Server Configuration Manager -> network then protocols for your SQL Server named instance -> TCP/IP.
See this image!
I have developed a web application in lightswitch. There is an HTML lightswitch client that connects to a server (C#) and this server gets the data from an SQL Database.
The application is working correctly in my local machine, the problem comes when I publish the solution to a Cloud Service in Azure. Then, the server connects to the database correctly and can read all the information from it, but when I try to update the database from within my application (insert or update rows) the application freezes and it promts the following error:
Unable to connect to SQL Server database.
Inner exception message:
Unable to connect to SQL Server database.
Inner exception 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 have checked the connection parameters and all of them are correct, this is the connection string in my web.config:
<add name="My_Data" connectionString="data source=tcp:{MyServer}.database.windows.net,1433;initial catalog={myDatabase};user id={Myuser}#{MyServer};password={MyPassword};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient" />
I have seen other questions with the same issue, but all of them were because the database or the server was not available. I have no problem connecting to the server because I can query my database with no problems.
The error comes when I try to write in my database, either because I click on the save button of a lightswitch screen or because I do it by code in the server:
serverContext.DataWorkspace.My_Data.SaveChanges();
If I comment the previous line, the error is not prompted.
I have also checked the user permissions in the database and this usser is a db_owner, so there should be no problem with that.
Anyone has ever faced a problem like this?
I found the solution!
After a deep research, I discovered that Azure server is adding a connection string to my application (I don't know how nor why). This connection string is inherited from somewhere and it is pointing to a local instance of SQL Express. Obviously, this instance does not exist, so after a timeout the application throws the error shown above.
I don't really know why this is happening nor why only happens when I try to write in my database. The solution I found is to add the following in the connection strings part of my web.config:
<clear />
With this, we delete the inherited connection string. And now, we have to set the connection string of the LocalSqlServer (which will be our connection string, the one that points to our remote SQL Server in Azure):
<add name="LocalSqlServer" connectionString="Data Source={SERVER}.database.windows.net;Initial Catalog={DATABASE};Integrated Security=False;User ID={USER}#{SERVER};Password={PASSWORD};Encrypt=True" />
Now, everything works fine. I hope this can help anyone who faces the same problem than me and I would really like to know why this happened, so if anyone knows it, please tell me :)
I already asked this question before, but without any good response,
my problem is that I have a local database (aspnetdb.mdf) in my app_data folder, here is the connection string in the web.config :
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
so my site works fine in my local iis server, but when i put the site in my host server, I get this 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).
In the other server I have sql server 2008 (the remote connection is accepted and i have the same instance name SQLEXPRESS). I really tried everything that I can but without any good results. I will really appreciate your help, thx.
This format indicates a local connection:
.\SQLEXPRESS
From another server, you'll need to specify a server name or IP address, e.g.:
192.168.1.205\SQLEXPRESS
YOURMACHINE\SQLEXPRESS
You'll also need to validate that the instance is SQL Server Express. From your other nearly identical question it looks like a default instance.
You should also stop using this silly user instance / attachDbFilename technique. Attach your database to the instance properly, then reference the logical database name using Initial Catalog=aspnetdb; in your connection string. This user instance feature was deprecated for multiple reasons, and this is certainly one of them.
Of course there may be other network issues that will prevent this, e.g. if the server is in a different domain, there are firewall settings interfering, etc. But your other server is never going to be able to access your machine using a dot for the server name.
EDIT providing baby steps because obviously my advice is not being followed. Assuming you have actually attached the aspnetdb database on the new server, try this please:
connectionString="data source=192.168.85.124\SQLEXPRESS;
Integrated Security=SSPI;
Initial Catalog=aspnetdb;"
If you aren't using SQL Express named instance after all, try:
connectionString="data source=192.168.85.124;
Integrated Security=SSPI;
Initial Catalog=aspnetdb;"
For SQL authentication use the same username/password you use in Management Studio:
connectionString="data source=192.168.85.124;
User ID=username; Password=password;
Initial Catalog=aspnetdb;"
This is troubleshooting 101 stuff. If you still can't get this to work, you may have to hire a consultant for 10 minutes to fix it for you since it's impossible to figure out what you've done and why you can't get it to work.
I have in Visual Studio two projects: My normal project and my test-project. I have chosen to use SpecFlow for testing and therefore my tests are UI based. So a database connection is not needed for the UI validation.
In some cases I have to set some preconditions to the system, like filling some sample data in the project. I've tried to connect my project-database to my test-project, but it just won't work. I tried to add connectionstrings to my test-project app.config like this:
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data Source=C:\Users\Martijn\Documents\VS11\Projects\Gastouderuren.nl\testprojectl\App_Data\example.sdf"
providerName="Microsoft.SqlServerCe.Client.4.0" />
</connectionStrings>
When I use this connection string in the code as follows:
MyContext context = new MyContext(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
context.Product.Count();
When I run my test, the following error occurs:
The provider did not return a ProviderManifestToken string. -> This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection. -> 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 searched already for a solution, but couldn't find anything. How can I solve this problem?
Thanks!
You cant connect to a external localdb (file based) like the same way you used to connect to normal SQL database
(connect string)
its because of localdb limits (No more than 1 apps can connect at once)
but i have a soulution : (How to use 2+ applications with 1 localdb)
You have to create a TCP server listener (In pc where LOCALDB is) and
X clients where your other pc(s) are
client pc(s) connect to server pc
So everytime you want to execute a sql command you send command from
CLIENT to SERVER and Server executes it ! (Can send back response to)
you can set some pre definded commands too(i did same thing)
SERVER :
if(CLIENT DATA . equals("ReadProducts"){
sql.execute("SELECT * FROM Products");
//convert...
SendBack(result);
}
CLIENT 1 >SEND> SERVER : "ReadProducts" (Predefinded command)
SERVER >SEND> CLIENT 1 : "Apple,Melon,Orange"
CLIENT 1 :
data = SERVER RESPONSE;
string[] sp=data.split(',');
//add a for loop which add all products to your listview
CLIENT 2 >SEND> SERVER : "INSERT INTO Products(name) VALUES(#name)"
SERVER :
if(CLIENT DATA . contains("INSERT"){
sql.execute(CLIENT DATA);
}
Using algorithm abow you can handle many connections to a single LocalDb file
from another computers but you have to deal with IP problem
get a Static Ip address for server app if you developing something big