how to put a webhostdatabase connection string in a winform application? - c#

i have myself tried a lot but i couldn't find out what is the problem of my below connection string. i have put both my webhost connection string and winform connection string help please?
<connectionStrings> <add name="ReGdbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;
provider=System.Data.SqlClient;
provider connection string="data source=.\SQLEXPRESS;
initial catalog=ReGdb;
integrated security=True;
MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings>
and here is my webhostdatabase connectionstring
Data Source=SQL5000322.Smarterasp.net;
Initial Catalog=DB_9BDB7789_ReGdb;
User Id=DB_9BDB7789_ReGdb_admin;
Password=happy;

hey bro you can modify your connection string this way and it must work. just copy and replace it with your connection string
<connectionStrings>
<add name="ReGdbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;
provider=System.Data.SqlClient;
provider connection tring=quot;
datasource=SQL5000322.Smarterasp.net;
initial catalog=DB_9BDB7789_ReGdb;
User Id=DB_9BDB7789_ReGdb_admin;
Password=happy;
MultipleActiveResultSets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
here you go bro it must work

Pay attention to nested quotes:
provider connection string="data source=...

Related

Keyword not supported 'data source' error

my connection string cannot login to my database.This is my connectionString
<add name="ProductEntities" connectionString="Data Source=**.**.***.**\MSSQLSERVER2017;Database=product1_;User Id=product;Password=*****;" providerName="System.Data.EntityClient" />
And these connectionStrings are that i tried in web.config
connectionString="Data Source=**.***.**.**\MSSQLSERVER2017;Network Library=DBMSSOCN;Initial Catalog=product1_;User ID=product;Password=*****;"
connectionString="data source=**.***.**.**\MSSQLSERVER2017;initial catalog=product1_;user id=product;password=*****;integrated security=True;MultipleActiveResultSets=True"
providerName="System.Data.EntityClient" />
and the other error is database cannot open.How can i fix this ?

Webconfig file not formed correclty

On my live box I am getting an error that the connection string is malformerd but when i try it on my dev box it is fine.
<add name="aperturenetEntities" connectionString="metadata=res://*/ApertureModel.csdl|res://*/ApertureModel.ssdl|res://*/ApertureModel.msl;provider=System.Data.SqlClient;provider connection string="data source=APR-AZ-DB01;initial catalog=aperturenet;user id=aperturenet;password=dw13£sowwoq;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="aperturenetSql" connectionString="Data Source=APR-AZ-DB01;database=aperturenet;User ID=username;Password=password" providerName="System.Data.SqlClient" />
They are both .net 4.5 boxes with no difference in sql version of the driver but yet i get malformed elements when running the application any idea?.
<add name="aperturenetEntities" connectionString="metadata=res://*/ApertureModel.csdl|res://*/ApertureModel.ssdl|res://*/ApertureModel.msl;provider=System.Data.SqlClient;provider connection string="data source=APR-AZ-DB01;initial catalog=aperturenet;user id=aperturenet;password=dw13£sowwoq;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
try this,
i have changed Application Name to App in your connection string.

connection string error

I have a connection string like this
<add name="rackleyConnectionString1" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\rackley.mdb;Persist Security Info=True;Jet OLEDB:Database Password=Password"
providerName="System.Data.OleDb" />
Now I copied that mdb file into my sql server. Now I changed connection string to this
<add name="rackleyConnectionString" connectionString="Data Source=ODO-SRV004;Initial Catalog=rackley;Integrated Security=True"
providerName="System.Data.SqlClient" />
when I run the program it shows error: "OLE DB provider was not specified in the connection string. An example would be Provider=SQLOLEDB"
Please help to solve this issue.
I hope you are opening sql connection as below
Dim cn As SqlConnection= New SqlConnection(sConn)
and not
Dim cn As OleDbConnection = New OleDbConnection(sConn)
I think You misplaced \ instead of /
<add name="rackleyConnectionString1" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/rackley.mdb;Persist Security Info=True;Jet OLEDB:Database Password=Password"
providerName="System.Data.OleDb" />
I always used /. please try this
<add name="rackleyConnectionString" connectionString="Provider=SQLOLED;Data Source=ODO-SRV004;Initial Catalog=rackley;Integrated Security=SSPI" />
Try this connection string hope this helps.

SQL Server Connection String: Web Hosting Service providing connection string that doesn't seem right

I have an ASP.NET C# application with a SQL server 2008 R2 database that has consolidated membership provider and application database. I am trying to modify my web config according to the instructions provided by the web hosting service provider but I think I'm missing something.
Here is my current web.config connection strings:
<connectionStrings>
<add name="RestaurantDB" connectionString="data source=SFP\SFP_SQL_SVR;attachdbfilename=C:\Users\Susan\Documents\Databases\Restaurants.mdf;Integrated Security=SSPI;"/>
<add name="RestaurantsEntities" connectionString="metadata=res://*/Restaurant.csdl|res://*/Restaurant.ssdl|res://*/Restaurant.msl;provider=System.Data.SqlClient;provider connection string="data source=SFP\SFP_SQL_SVR;attachdbfilename=C:\Users\Susan\Documents\Databases\Restaurants.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Here is the connection string that the web hosting service has given me:
Data Source=RESTAURANT.db.9319451.hostedresource.com; Initial Catalog=RESTAURANT; User ID=your username; Password='your password';
How do I modify my current connection strings in light of the above? Thanks in advance.
Just replace data source=SFP\SFP_SQL_SVR;attachdbfilename=C:\Users\Susan\Documents\Databases\Restaurants.mdf;Integrated Security=SSPI;
to
Data Source=RESTAURANT.db.9319451.hostedresource.com; Initial Catalog=RESTAURANT; User ID=your username; Password='your password';
Like :
<add name="RestaurantDB" connectionString="data source=RESTAURANT.db.9319451.hostedresource.com;
Initial Catalog=RESTAURANT; User ID=your username; Password='your password'>
<add name="RestaurantsEntities" connectionString="metadata=res://*/Restaurant.csdl|res://*/Restaurant.ssdl|res://*/Restaurant.msl;
provider=System.Data.SqlClient;provider connection string="Data Source=RESTAURANT.db.9319451.hostedresource.com;
Initial Catalog=RESTAURANT; User ID=your username; Password='your password;
multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
I have no idea how to deal with this but I'm just giving you an idea. Try it may be it works
First modify your RestaurantDB connection string like this
<add name="RestaurantDB" connectionString="RESTAURANT.db.9319451.hostedresource.com;Initial Catalog=RESTAURANT; User ID=your username; Password='your password';"/>
and RestaurantsEntities like this
<add name="RestaurantsEntities" connectionString="metadata=res://*/Restaurant.csdl|res://*/Restaurant.ssdl|res://*/Restaurant.msl;provider=System.Data.SqlClient;provider connection string="data source=RESTAURANT.db.9319451.hostedresource.com;Initial Catalog=RESTAURANT;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
If the above does not work then also add UserID and Password in the RestaurantsEntities connection string

How to connect database by using username and password in .net c#

I'm new to .net c#, hope this question is not sound silly. How can I connect to the database in web.config by using the username and password??
Example:
Following is the connection strings that I used to connect to the database. How could I write/set so that I can set the username (username = test) and password (password = abc123) for this connection strings and so that it will allows me to access to the database?
<connectionStrings>
<add name="aConnectionString" connectionString="Data Source=AAA-LLLL-SQL-00;Initial Catalog=Database_Name;Connect Timeout=1;Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Try something like this.
<connectionStrings>
<add name="aConnectionString" connectionString="Data
Source=AAA-LLLL-SQL-00;Initial Catalog=Database_Name;User Id=myUsername;Password=myPassword"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Use this to pull your connection string from the web.config.
http://msdn.microsoft.com/en-us/library/ms178411.aspx
Then you will use the .net Sql Provider to create a connection.
using(SqlConnection con = new SqlConnection(connectionstring))
{
con.Open();
// Perform operations here
}
Are you trying from IIS?
Then you need to grant your App Pools account access to SQL Server.
CREATE LOGIN [IIS APPPOOL\ASP.NET v4.0] FROM WINDOWS WITH DEFAULT_DATABASE=[AAA-LLLL-SQL-00], DEFAULT_LANGUAGE=[us_english]
GO
Reference for ADO and ADO.NET connection strings http://www.sqlstrings.com/
<connectionStrings>
<add name="aConnectionString" connectionString="Server={ip};Database= {databasename}; User Id={username}; Password={password}"/>
</connectionStrings>
This should work replace {...} with your values.
<connectionStrings>
<add name="aConnectionString" connectionString="Data Source=AAA-LLLL-SQL-00;Initial Catalog=Database_Name; User Id=your username; Password=pwd;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Categories

Resources