So, after the last weekend I have been having serious trouble connecting to an SQL database through the Visual Studio environment.
This is the enviroment
My OS is Windows 8.1 Enterprise
I'm running Visual Studio Community 2013, and develop in VB
The SQL server is located off site. The version is 12.0.2269. I do not administrate this one, but it is the back-end for the company ERP system so it is running on stable platforms and working well for hundreds of users.
In VS, I have a connection string set up under Project Settings:
Data Source=a.b.c.d;Initial Catalog=dbName;Persist Security Info=True;User ID=xxx;Password=yyy
(Connection uses ".NET Framework Data Provider for SQL Server")
This is what I have tried
The SQL server answers to ping
I can connect to the database through Microsoft SQL Server Management Studio 12.0.2000.8
In VS, under Project Settings, I can open the connection string configuration dialog. When I click "Test Connection" everything works fine (Test connection succeeded).
If I start the application I am developing it can connect to the database without problem.
BUT, if I go to the dataset designer, right click a TableAdapter and select Preview Data..., the application hangs for a while and then this error message comes up:
A network-related or instance-specific error occurred while establishing a connection to the 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).
I should also mention that this worked before last weekend. I have not changed anything to the project. The only change I can see is several windows updates installed during the weekend.
This seems to affect only one particular project. Connections to the same database seems to work well in other solutions.
I have no idea what to do from here. Have this happened to anyone else?
My connection is like that and work, try with that:
Public Function FunctionConnection() As SqlConnection
FunctionConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\TCO_Orders.mdf;Integrated Security=True;User Instance=True")
'FunctionConnection = New SqlConnection("Data Source=;Initial Catalog=DATABASE;Persist Security Info=True;User ID=;Password=")
Return FunctionConnection
End Function
Related
I have deployed a website to IIS and it is trying to access the database via the connection string.
My SQL Server and connection string is correct as I have tested it in the following ways:
My development environment streams data correctly
Connection to SQL Server is good as I could see from SQL Server Management Studio
Other pages of the website that are deployed are correct and only those pages that stream data is failing.
The problem is that it is only through the IIS website we have this error and when I run it from Visual Studio it is all right.
Here is the stack code I get:
Stack trace error
My connection string:
<add name="cnnSQLDB"
connectionString="server=**********;database=*********;Integrated Security=True;User ID=******;Password=******;"
providerName="System.Data.SqlClient"/>
Make sure that port 1433 is open on your firewall. That is the port SQL Server uses.
I was able to solve this issue based on hints provided here. I had to do the following changes:
Update the SQL connection string and set "Integrated security=false". In that way it will use the login credentials provided in the SQL connection string.
Create a new user as provided in the SQL connection string and GRANT the necessary accesses.
When I copied the databases from the production environment to a new environment the GRANT permissions for the user mentioned in the connection string was not updated.
But by checking the port status via the command 'sp_readerrorlog' gave me clues and led me to a solution. Some other links that helped me were: this and this
I am trying to install an ASP.NET 5 Web application on IIS 7.5, and am running into a database connection issue. When running the application in the development environment the data source is set to (LocalDB)\v11.0, Which I believe is not correct. I get an error when browsing the web application on the remote server where IIS is located,
The system cannot find the file specified:
[SqlException (0x80131904): 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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
How do I form the connection string so that my application can reach the database to match models I created with the entity framework in Visual Studio 2013?
I think something like this would be suitable:
<add name="MyDB" connectionString="data source=ServerName; initial catalog=MyDB; attachddbfilename=|DataDirectory|\MyDB.mdf; integrated security=True;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.SqlClient" />
Judging by your error, it looks like you don't have a local database runtime installed.
If you are going to use SQL Server Express 2012, you will need to download and run the installer SqlLocalDB.MSI and use the connection string (LocalDB)\v11.0.
If you are going to use SQL Server Express 2014, you will need to download the 2014 installer SqlLocalDB.MSI and use the new connection string (LocalDB)\MSSQLLocalDB.
We have solution based on Windows Mobile 6.5.3 and use System.Data.SqlClient to connect to our database. Everything works fine until...
After upgrade SQL Server from 2005 Workgroup Edition to 2012 standard we have problem with connections.
Real device can connect to SQL server - application works, but we can't debug project on emulators. This is strange why real device can work on that connection string. When we debug using real device we can connect to db while on emulator, we can't
W spend 2 days on searching solutions with no result.
My SQL Connection looks like
Server=xx.xx.xx.xx\InstanceName,1433;Database=dbName;User Id=userName;Password=password;Connect Timeout=30
When we call SqlConnection.Open() exception occurred.
using (var sqlConnection = new SqlConnection(DatabaseConstans.ConnectionString))
{
sqlConnection.Open();
We did:
change default SQL port number to 1433
cradle emulator - internet browser test - passed
SQL Browser is working
we can connect from WinForm application on that connection string
Other settings:
You will need to install SQL Server Management Studio 2008 R2 (a free version is available) to open SQL CE (.SDF) files. On Connect in Object Explorer, it will provide option for SQL Server Compact..., in addition to Database Engine.
Remove your SQL Instance name (eg SQLEXPRESS) from the Connection string.
In SQL Configuration Manager under TCP/IP Protocols, Clear ALL TCP Dynamic Ports (leave blank). Set TCP Port to 1433 under "IPALL"
So your connection string should look like:
Data Source=192.168.1.53,1433;Initial Catalog=dbname;User ID=xxx;Password=xxxxx;"
This worked for me after 2 full days of trying to figure it out.
I have a project created while running 2008r2 express and connecting to an instance named "Sqlexpress". I have recently uninstalled Sql server 2008r2 express and started using the recommended LocalDB. All of my projects updated the database successfully and connect flawlessly with the exception of one, my largest project.
The database updated perfectly but now i get a Error 26 - Network or instance related error each time i try to login in. (iterating through a dataset created in the dataset desinger.
Here is my connection string:
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True
I can see the connection in Server Explorer and view table data. Any idea why this wouldn't work at runtime on this one project?
I solved this by opening Dataset.Designer.vb in notepad++ and replacing all instances of ".\SQLEXPRESS" with "(LocalDB\v11.0". I also had to set each instance of "User Instance=True" to False.
I solved the same by replacing the "(localdb)\v11.0" with applicable "MyServerName\SQLServerInstanceName" in connection string. During the installation of SQL Server Express 2014, I chose to keep SQLExpress as instance name.
first I have checked that Server Authentication is already set to:
"SQL server and Windows Authentication mode" (mixed mode)
้here 's my web.config connectionstring
<connectionStrings>
<add name="StockConnectionString" connectionString="Data Source=192.168.0.2;Initial Catalog=Stock;Persist Security Info=True;User ID=op;Password=operator" providerName="System.Data.SqlClient"/>
</connectionStrings>
Whene I test running (ctrl+F5) under VS2010 development this can connect to remote SQL server without any problem. but when i publish this project to local IIS (same web.config) an error occured..
Login failed for user 'op'. Reason:
Not associated with a trusted SQL
Server connection.
also i can connect to SQL server via SQL server Management Studio with SQL server authentication same user/pass.
no idea what's wrong with this.
finally, after 3 days can't figure this out. then i tried start over.
created a new project (ASP.NET MVC 2 web app) in VS2010.
go to Database Explorer > Add Connection..
use SQL server authentication to remote SQLserver directly instead of local.
then gotcha!! it told me..
this server version is not supported. you must have Microsoft SQL server 2005 or later.
my project was created under Win XP connect to SQLserver 2000 and it's work fine. now the answer for an error above is..
Visual Studio 2010 dropped support for SQL Server 2000. You'll either have to go back to VS2008/SL3, upgrade your SQL Server, or do things manually outside of Visual Studio.
...really appreciate this so much
Does it make any difference if you add this to the connection string ?
Trusted_Connection=False;
A clue is that it's saying that it's not trusted which indicates it's not using the username and password from the string. Has a connection string been possibly imported into IIS ?
Trusted is windows authentication which by the error is being used. Sql server authentication is username and password which you are trying to use.