I have a connectionstring in my xamarin android project:
`<add name="NewsPushEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source=ROONEY;Initial Catalog=NewsPush;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient" />`
when I first open my project I get the state as closed.
But when I click to expand the connection in the server explorer it turns green:
However when I am trying to fetch something in my application by calling the said connectionstring it returns emptyhanded (It's a rest-service returning a menu in Json format, It works when I connect to the live server but not my local one.)
connection to live server:
<add name="NewsPushEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="data source=removed;initial catalog=NewsPush;persist security info=True;user id=removed;password=removed;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Last but not least when my state is open (after expanding my connection and it turns green) I get the following properties:
Did I bum up on the connectionstring somehow? Not sure how to get this to respond. Thanks!
If you are not getting any errors, debug your service in your local machine and use the watch window to determine if your connection string is correctly set.
Related
I have been trying to open my SQL Server database in Server Explorer, and I'm always getting the following error
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was -[Pre-Login] initialization=18214; handshake=118555;
I've tried to fix the issue by repairing the VS2019, and that didn't work.
Edit: The database is running locally from my PC.
And this is the connection string from Web.config file:
<add name="UserEntities" connectionString="metadata=res://*/Models.UsersModel.csdl|res://*/Models.UsersModel.ssdl|res://*/Models.UsersModel.msl;provider=System.Data.SqlClient;provider connection string="data source=Mizile;initial catalog=Login;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
You're connection string is incorrect. If SQL Server is on your machine locally, or on your network then it CAN look something like this,
<add name="UserEntities" connectionString="Data Source=YourSqlInstanceName;Initial Catalog=YourDatabaseName;Integrated Security=True" providerName="System.Data.SqlClient" />
You can of course read MS docs about different types too.
https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/creating-a-connection-string
I have an answer that I posted previously here:
Connection string
Please follow the steps to get your connection string, if successful share your experience and mark as answered else let us know where you are stuck that I will edit with more help.
I installed a windows form application on a client computer but when I try to log into my application it gives me this error:
a connection was successfully established with the server, but then an error occurred during the login process. (provider: shared memory provider, error: 0- No process is on the other end of the pipe.)
This is a c# windows form application running with SQL Server database, with login details. I have added the in and out bound rule on my firewall, I have tried changing my connection string severally, I have enabled tcp/ip port with its default port number, I have tried using the same network for both computers, I have tried using window and sql authentication, I have disabled firewall on client computer
Here is my connection string
<add name="connstrng" connectionString="Data Source=(local);Initial Catalog=AnyStore;Integrated Security=True"/>
I expect to be logged in to my application on the client computer using the same database with my server computer.
Connection strings are usually defined within the Web.config file. As #Panagiotis Kanavos said, the string is connecting to a local data source, which should work as expected within your dev environment. The web.config file should be located within the root directory of your project. Edit this file on the client's machine to point to the expected server / database. You may want to keep a blank or default version of this file in source control to avoid overwriting other's connection string info.
Example String:
<add name="SomeDB" connectionString="Data Source=snapdragon\SQL2k14;database=DBNAME;User Id=username; password=password" providerName="System.Data.SqlClient" />
Edit: "snapdragon" would be the host computer name. "SQL2k14" would be your sql server instance.
ok, i found the solution i changed my connection string and its working fine now, thanks guys.
here is my connection string-
<connectionStrings>
<add name="connstrng" connectionString="Data Source=DESKTOP-5I8TFY3\EMEKA;Initial Catalog=AnyStore;User ID=adminpos;Password=********" />
</connectionStrings>
</configuration>
I've seen this error answered for other people, but I can't seem to get it to work. I'm trying to connect to a SQL Server Database project locally.
I'm getting this error thrown on Open() when I do the follow:
SqlConnection conn = null;
conn = new SqlConnection(connection)
conn.Open()
Where connection is a connection string passed from my webconfig. I've found examples online and tried these three connection strings and I get the same error every time:
<add name="TICKETING_CONNECTION" connectionString="Server=(local); DataBase=Ticketing_DB; Integrated Security=SSPI"/>
<add name="CONN"
connectionString="Data Source=localhost; Integrated Security=SSPI;Initial Catalog=Ticketing_DB"
providerName="System.Data.SqlClient" />
<add name="CONN2"
connectionString="Data Source=(local);Initial Catalog=Ticketing_DB;"
providerName="System.Data.SqlClient"
/>
Could the problem be stemming from the path of where the database is located on my machine? I've tried copying the c:\ path but didn't have any luck. I've seen some examples online use a .mdf file, but my project does not have this file either.
This is my first time trying to connect to a database project, so any help or advice would be greatly appreciated
If you are using Visual Studio try going to the Server Explorer and Right click on Data Connections and Add new connection by selecting DataSource as Microsoft SQL Server and provider as .net framework provider for SQL Server.
Under the server name check for the SQL Server if it is listed with your machine name.
Then try to provide the database details and user name and password for SQL Authentication or select windows for windows authentication. Then do a test connection. If it is fine on click of OK it will add the data connection.
Right click the properties of data connection which is newly added and navigate to properties to extract the connection string. Compare it with yours. This can help you troubleshoot the issue.
I have a desktop app that I am nearing finishing proof of concept on but I have a final function I want to add but I do not think it is possible
The app which will finally be deployed uses Entity Framework and is written in VS 2010. The app needs to be deployed in two different companies which have the same SQL database structure (but different names Database1 or Database2) but they are hosted on different servers (eg Server1 and Server2)
It would be neat to be able to set Server1 or Server2 and Database1 or Database2 in a wpf form and "save" the application setting rather than have to deploy twice with different EF models.
This means writing over the app.config file at run time and from reading around this seem difficult see here but this refers to general settings not the configuration string or am I missing the point
In my case should my app.config is
<connectionStrings>
<add name="OsmiContext"
connectionString="metadata=res://*/OsmiModel.csdl|res://*/OsmiModel.ssdl|res://*/OsmiModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=**Server1**\**DATABASE1**;Persist Security Info=True;User ID=<STANDARDUSER>;Password=<STANDARDPASSWORD>Qu3r3y3;MultipleActiveResultSets=True;Application Name=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
So I think my code should look something like this I think (the String NewConnection would in fact be built in the method at run time) Am I right or missing something?
<build so new App.Config Method>
String NewConnection =#"metadata=res://*/OsmiModel.csdl|res://*/OsmiModel.ssdl|res://*/OsmiModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=**Server2**\**DATABASE2**;Persist Security Info=True;User ID=<STANDARDUSER>;Password=<STANDARDPASSWORD>Qu3r3y3;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient"
string appPath =System.IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location);
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
config.AppSettings.Settings["OsmiContext"].Value = NewConnection ;
config.Save(ConfigurationSaveMode.Modified);
i use Entity framework in .net 4 and use this connection in project:
<add name="Database1Entities" connectionString="metadata=res://*/Model.Model1.csdl|res://*/Model.Model1.ssdl|res://*/Model.Model1.msl;provider=System.Data.SqlClient;pr ovider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\Database1.mdf;initial catalog=Database1;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
and show this error:
The underlying provider failed on Open.
I don't know why you get this error but I use this connection string and I don't have any problem.
remember the name of the DbContext class and connection string should be same
<add name="MyDB"
connectionString="Server=127.0.0.1;User ID=sa;Password=password;Database=Database"
providerName="System.Data.SqlClient"/>
The problem is not in your connection string. This is mostly happen when you are rebuild and clean the project again and again. there is a simple way to solve this problem is that close your local host and wait 2 to 3 minutes. If you face this problem again then close your project and open your project again. Your problem will sort out.