what would be the connection string for below in web.config? - sql

I have written something like this but i am getting error as invalid username.
any suggestions?

You can simply set Connection String in the Web Config file and just reference it based on your requirements.. see below
Web Config:
<connectionStrings>
<add name="SQLDBConnectionString" connectionString="Data Source=<SERVER NAME>;Initial Catalog=<DATABASE NAME>;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Then to get reference with the connections:
public string SQLServerDBConnstring()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["SQLDBConnectionString"].ToString();
}

Related

Have a problem with Format of the initialization string does not conform to specification starting at index 132

Controller
if (User.Identity.IsAuthenticated)
{
var users = adminDatabase.AspNetUsers.Where(u => u.UserName ==User.Identity.Name).FirstOrDefault();
Session["CurrentUser"] = users;
}
Connection
<add name = "DefaultConnection"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=administration;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
The problem that showed me is on controller user identity.
I have no idea what's going on!

How to debug this database connection string?

SqlConnection con = new SqlConnection("Server=ACER-PC/SQLEXPRESS;Database=coupon;Integrated Security=true");
What's wrong in this?
A connection string for SQL Server should look more like: "Server= localhost; Database= employeedetails; Integrated Security=True;"
If you have a named instance of SQL Server, you'll need to add that as well, e.g., "Server=localhost\sqlexpress".
If it is not windows authentication then connection string will look like this,
Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
try this
add this code in web config file
<connectionStrings>
<add name="ProjectConnectionString" connectionString="Data Source=ACER-PC/SQLEXPRESS OR Your system ip address;Initial Catalog=coupon;Integrated Security=false;user=username;password=password"/>
</connectionStrings>
then initialize your connection string like
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ToString());

Cannot connect to database mvc

I cant connect to database, working on new pc.
Here are params with which i access my sql database :
My connection string in Web.config is :
<connectionStrings>
<add name="DefaultConnection" connectionString="data source=DMITRIJSS-PC\SQLEXPRESS;initial catalog=HRM_MVC_DEV_Test;user id=BTG\DmitrijsS;password=;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
<add name="HRMEntities" connectionString="metadata=res://*/HRMModel.csdl|res://*/HRMModel.ssdl|res://*/HRMModel.msl;provider=System.Data.SqlClient;provider connection string="data source=DMITRIJSS-PC\SQLEXPRESS;initial catalog=HRM_MVC_DEV_Test;user id=BTG\DmitrijsS;password=;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
When I am trying to access db it throws window where I have to write password, when I leave it blank -
Login failed for user BTG\DmitrijsS
<add name="DefaultConnection" connectionString="data source=DMITRIJSS-PC\SQLEXPRESS;initial catalog=HRM_MVC_DEV_Test;Integrated Security=true;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
<add name="HRMEntities" connectionString="metadata=res://*/HRMModel.csdl|res://*/HRMModel.ssdl|res://*/HRMModel.msl;provider=System.Data.SqlClient;provider connection string="data source=DMITRIJSS-PC\SQLEXPRESS;initial catalog=HRM_MVC_DEV_Test;Integrated Security=true;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Set up environment variables.
https://msdn.microsoft.com/en-IN/library/ms365307.aspx

The connection string 'ClinlabEntities' in the application's configuration file does not contain the required providerName attribute."

I am using IIS 8 and MVC4 Application I am having an error..
Thank You for your Help.
<connectionStrings>
<add name="ClinlabConnectionString1" connectionString="Data Source=.\sql2012;Initial Catalog=Clinlab;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
The connection string in the message error ClinlabEntities is not the same that you posted ClinlabConnectionString1, you should look for ClinlabEntities connection string and add the providerName attribute.

How to declare ConfigurationManager.ConnectionStrings?

hello i'm using visual studio 2008, vb.net and oracle as my db.
this is what i save in my apps.config
<appSettings/>
<add key="SMSDW_connection" value="server=abc;database=efg;User ID=**;Password=**;"/>
and this is my code for calling the apps.config file :
Dim connectionString = System.Configuration.ConfigurationManager.AppSettings("SMSDW_connection")
Dim sqlConnection As OracleClient.OracleConnection = New OracleClient.OracleConnection(connectionString)
but still i got an error which is :
The ConnectionString property has not been initialized.
i have add reference System.Configuration and Imports System.Configuration
The <appSettings> node has the closing tag "/" so the <add is outside of it.
it should read:
<appSettings>
<add ...
</appSettings>