I know my question is basic.
But I don't Know how should I configure web.config information!
My SQL server is connected with windows authentication.
I'm using this config:
<add key="DBServer" value="mssql" />
<add key="DBSource" value="localhost" />
<add key="DBName" value="TestDB" />
<add key="LoginName" value="KARIM-PC\Karim" />
<add key="LoginPWD" value="" />
but I get this error:
{"This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection."}
Exception: Thrown: "Login failed for user 'KARIM-PC\Karim'."
(System.Data.SqlClient.SqlException) A
System.Data.SqlClient.SqlException was thrown: "Login failed for user
'KARIM-PC\Karim'."
Add either <add key="TrustedConnection" value="Yes" /> or <add key="IntegratedSecurity" value="SSPI" />to force Windows Authentication.
You can read more here.
For Window Authentication
<add name="MyDbConn" connectionString="Initial Catalog=MyDataBaseNAme;Data Source=MyServerName;Integrated Security=SSPI;"/>
I recommend you this site: https://www.connectionstrings.com/sql-server/ for getting more information about connection strings.
In your case I think it will suits you:
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
Related
Over here Nuget connection attempt failed "Unable to load the service index for source" I saw many solutions proposed for the
Unable to load the service index for source ...
Error that I find myself getting on an attempted dotnet build right now.
I see suggestions to put XML like either of these
<packageSourceCredentials>
<vstsfeed>
<add key="Username" value="yourname#company.com" />
<add key="Password" value="this is an encrypted password" >
<!-- add key="ClearTextPassword" value="not recommended password" -->
</vstsfeed>
</packageSourceCredentials>
<config>
<!-- Proxy settings -->
<add key="http_proxy" value="host" />
<add key="http_proxy.user" value="username" />
<add key="http_proxy.password" value="encrypted_password" />
</config>
Into Nuget.Config.
How are the passwords encrypted? What should go into the encrypted_password placeholder spaces?
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.
I am trying to connect my C# application to an oracle database using Oracle.ManagedDataAccess. However, when I try to create the database it gives me the error below. Any ideas as to what I'm setting up incorrectly? I know that the provider name is set correctly, because I'm able to connect to the database exactly the same way with another C# application.
"The requested database ConnectionString.SomeName does not have a valid ADO.NET provider name set in the connection string"
On machine.config:
<add name="ConnectionString.SomeName" providerName="Oracle.ManagedDataAccess.Client" connectionString="Data Source=databaseSource;User Id=some_id;Password=some_password" />
On web.config:
<appSettings>
<add key="ConnectionString1" value="ConnectionString.SomeName"/>
</appSettings>
My code:
DatabaseProviderFactory factory = new DatabaseProviderFactory();
Database = factory.Create(ConfigurationManager.AppSettings["ConnectionString1"]);
In the Machine.config, check to ensure that you have two sections setup. One in " and another in . Examples below:
<appSettings>
<add key="ConnectionString.SomeName" value="Data Source=databaseSource;User Id=some_id;Password=some_password"/>
</appSettings>
<connectionStrings>
<add name="ConnectionString.SomeName" connectionString="Data Source=databaseSource;User Id=some_id;Password=some_password" providerName="Oracle.DataAccess.Client"/>
</connectionStrings>
The 'key' in your appSettings entry should match the 'name' in your connectionStrings entry.
For example, in your case, you should have this entry in appSettings:
<add key="ConnectionString.SomeName" value="Data Source=dataSource;User ID=some_id;Password=some_password" />
The solution that worked for me is to add the following to the App.config / Web.config (within the configuration tag):
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
I am using basic authentication for my web api and am getting the following error
*{"Message":"An error has occurred.","ExceptionMessage":"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: Named Pipes Provider, error: 40 - Could not open a connection to SQL *
It works absolutely fine when i remove the basic auth implementation from my APIs. So am guessing the problem should be something related to system.web.providers which am using for the basic auth implementation.
This is how my connection string looks like
<connectionStrings>
<add name="DefaultConnection" connectionString="Password=password;Persist Security Info=True;User ID=wbuser;Initial Catalog=WinBouts_com;Data Source=WINBOUTSAPIVM"
providerName="System.Data.SqlClient" />
<add name="WinBoutsConnectionString" connectionString="Password=password;Persist Security Info=True;User ID=wbuser;Initial Catalog=WinBouts_com;Data Source=WINBOUTSAPIVM"
providerName="System.Data.SqlClient" />
And i see an error in my web.config where a session provider is added. The error says "the connectionStringName attribute is not allowed". But if i remove it then it asks for the connectionStringName. This is the code for it.
<!--
If you are deploying to a cloud environment that has multiple web server instances,
you should change session state mode from "InProc" to "Custom". In addition,
change the connection string named "DefaultConnection" to connect to an instance
of SQL Server (including SQL Azure and SQL Compact) instead of to SQL Server Express.
-->
<sessionState mode="Custom" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="WinBoutsConnectionString" />
</providers>
</sessionState>
Can anyone please tell me where i might be going wrong? Any suggestions or ideas would be deeply appreciated.
Finally Resolved the issue. The problem was in my Basic Authentication filter class.
private bool TryGetPrincipal(string username, string password, out IPrincipal principal)
{ string connectionString = ConfigurationManager.ConnectionStrings["WinBoutsConnectionString"].ConnectionString;
username = username.Trim();
password = password.Trim();
//only supporting SSO login atm
// var valid = Membership.Provider.ValidateUser(username, password);
serviceContext = new WinBoutsDataContext<DataAccess.Model.UserInfo>(connectionString);
userRepository = new UserRepository(serviceContext);
var valid = this.userRepository.ValidateAccount(username, password);
if (valid)
{
// once the user is verified, assign it to an IPrincipal with the identity name and applicable roles
principal = new GenericPrincipal(new GenericIdentity(username), System.Web.Security.Roles.GetRolesForUser(username));
return true;
}
//user wasn't found, unauthorised
principal = null;
return false;
}
I have hardcoded my DataContext here but earlier i didnt pass my connection string into it. I just went for the default constructor of the WinBoutsDataContext which didnt work when i put the code on to the server.
If you want to use a defined connectionString, you have to use the name of the connection string to fill the "sqlConnectionString" attribute and use SqlServer mode :
<configuration>
<connectionStrings>
<add name = "myString"
connectionString = "data source=local;user id=User;password=password" />
</connectionStrings>
<system.web>
<sessionState
mode="SQLServer"
sqlConnectionString="myString"
cookieless="false"
timeout="20"
/>
</system.web>
</configuration>
according to :
http://msdn.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx
if im using sql 2005 i have to write this :
<configuration>
<connectionStrings>
<add name="Northwind" connectionString="Data Source=(local); Initial Catalog=northwind; Integrated Security=true"; providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependency enabled = "true" pollTime = "60000" >
<databases>
<add name="northwind"
connectionStringName="Northwind"
pollTime="9000000"
/>
</databases>
</sqlCacheDependency>
</caching>
</system.web>
</configuration>
but what about sql 2008?
i'm enabling the service broker ,
i'm creating sqlCacheDpendency and put there the Command
and when i change the Table , it doesn't remove the cached item.
Read The Mysterious Notification to understand how it works and then you can understand how to troubleshoot it (or cheat out with ssbdiagnose). Most likely the EXECUTE AS context of the database was invalidated by orphaning the dbo due to database movement. The transmission_status value in sys.transmission_queue would clearly show it. If true, the fix is to map dbo to a valid login:
ALTER AUTHORIZATION ON DATABASE::[<dbname>] TO [sa];
Otherwise the solution depends o the problem cause, use the troubleshooting steps linked above.