I'm stymied by a problem I'm having reading a connection string for a Web API app.
I have a connection string set up in app.config as follows:
<connectionStrings>
<add name="connectionString" connectionString="Server=[server];Database=[db];User Id=user;Password=password;"/>
</connectionStrings>
This is read from code as:
string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
All works fine in development (using the proper creds of course). However when I publish, the app.config is not copied over. I can manually recreate this file on the server, but even then I get the following error:
Login failed for user '[MACHINE NAME]'.
It appears that instead of grabbing the connection string from app.config the code is instead attempting to connection to SQL Server using a trusted connection.
Note that I'm using ADO and not EF.
Any ideas?
Related
Initially I developed my project by putting the .db file within the project folder. Now I want to host the database on localhost so I put the db file on a new folder and started a http-server using node.js on localhost:8080. To start the server I used this command on node.js command line C:\Users\Me\aswserver>http-server .
aswserver folder contains only aswDB.db.
On my C# project until now I used the connection string
<connectionStrings> <addname="SQLite"connectionString="DataSource=.\aswDB.db;Version=3;"providerName="System.Data.SQLClient"/>
</connectionStrings>
and included the db file to project(Build Action: Content and Copy to output if newer).
After hosting the db on localhost I tried this connection string
<connectionStrings>
<add name="SQLite" connectionString="Data Source=localhost:8080/aswDB.db;Version=3;" providerName="System.Data.SQLClient" />
</connectionStrings>
Now when I try to connect to the db from the project I get Exception saying "The given path's format is not supported". How do I set up the connection so that any change I make to the db stays in aswDB.db on the server? (I plan to connect it to a Xamarin.android app too)
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 bought a Windows hosting from GoDaddy. I have configured the configuration settings(Adding database and publishing project's files to host)
I can access the database while running the project on the local server.
But when I transfer the project to the server, the project on the server can't do it.
I wrote my connection string to web.config file, here it is:
<add name="xyz" connectionString="Data Source=IP ADDRESS;Initial Catalog=DBNAME;User ID=USERNAME;Password=PASS;Integrated Security=False" providerName="System.Data.SqlClient" />
I used MVC and Entity Framework, I also used layered structure
Thank You.
try to check more details about the connection string that should be used with your database provider. Here you can find several examples about how to create your connection string properly in SQL SERVER.
please notice that if you are working in your host machine, you have not to specify the IP ADDRES of your SQL SERVER but the SERVER NAME just like:
Data Source=(SERVER_NAME) \ DB_INSTANCE_NAME
I hope that it's gonna be useful.
I have a WPF application holding a LINQ to class database, now I need to publish this application to work on client's machine.
I have done this but it doesn't work like if the database was not found, I think my problem is that the database is not included in the deployed files, so I need help with a clear steps to publish my application including my database.
Thanks in advance
It's not possible to interact with your .mdf database without having SQL Server engine installed on your client machine .
Try this:
Install SQL server Express on your Client machine
Attach database to the SQL Server (using .mdf or using a DB backup)
then change your connection string before deploying the application in client machine.
if you've hard coded the connection string then , you'll have to change the connection string to adjust client's machine name , or add you connection string inside app.config in order to give you the flexibly to modify it after deployment .
App.Config:
<configuration>
<connectionStrings>
<add name="Test" connectionString="Data Source=.;Initial Catalog=OmidPayamak;IntegratedSecurity=True" providerName="System.Data.SqlClient" />
</connectionStrings>
using
var connection = ConnectionFactory.GetConnection(ConfigurationManager.ConnectionStrings["Test"].ConnectionString, DataBaseProvider);
wish it help .
I need to deploy WCF. Database is SQL Server 2008 R2. Access to database is only possible from app server because of Windows Authenticaton (sql server authentication not work).
I need to change my connection string to new data source i tried but not successfull.
i have connection address and everything what i need.
My connection string :
<connectionStrings><add name="MyEntities" connectionString="metadata=res://*/MyDatabase.csdl|res://*/MyDatabase.ssdl|res://*/MyDatabase.msl;provider=System.Data.SqlClient;provider connection string="data source=myMachine-LAPTOP;initial catalog=MyDatabaseName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings></configuration>
to delete connection string and generate new is not possible, because i have not access from dev computer and app server dont have visual studio to try it from there.
i need help how to change it.
Please try to change connection string by opening configuration file with notepad..