i am having trouble with the Connection String in C#
the database is on the server via phpmyadmin(i do not own the server its online)
got hosting via GoDaddy as well as GlobeHost but with both same problem
my current connection srting is string strcon = "Server=ipAddress(OfServer);Database=testing;Uid=myusername;Pwd=mypassword";
and i am getting this error while Connection.Open();
check the link testing page
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=**************' failed.
Your web host has configured the server to block outbound connections, at least specifically on your website and possibly that port number.
Speak to your web host to find out if you can be granted permission or if other ports are unblocked (though this is a Code Access Security configuration, so I doubt it depends on the port setting at all) - if not then you will not able to use an external database at all.
Note that using an off-site DB will generally result in very poor performance because of network latency. Is there a reason you're not using a DB provided by your host?
Connection String format is wrong. It has to be
connectionString="Server=192.168.0.XX;Database=DBname;User Id=bdusername;Password=dbpassword;"
Related
I've being trying in vain to solve a problem on a newly created windows server with IIS hosting an ASP.NET application that was copied from another environment. The issue is that I cannot manage to connect to the database when the application tries to open a connection via entity framework.
If this is off topic for SO let me know so I can move to another channel, I thought it belonged here as seems specific to EF.
In detail, I have the following connection strings:
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=LOCALCOMPUTER\SQLEXPRESS;Initial Catalog=xxx;Persist Security Info=True;User ID=yyy;Password=zzz" providerName="System.Data.SqlClient"/>
<add name="MembershipConnection" connectionString="metadata=res://*/App_Code.Membership.Membership.csdl|res://*/App_Code.Membership.Membership.ssdl|res://*/App_Code.Membership.Membership.msl;provider=System.Data.SqlClient;provider connection string="Data Source=LOCALCOMPUTER\SQLEXPRESS;Initial Catalog=xxx;Persist Security Info=True;User ID=yyy;Password=zzz;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient"/>
...
xxx, yyy, zzz of course have the proper values. LOCALCOMPUTER is the FDQN of the local computer, which is not on a domain
The first connection string is for the Microsoft login library, while the second uses entity framework from our code.
When I browse to the site, I can successfully access the login form, and if I try to insert a wrong password i get a message saying so, meaning the application managed to check the database using the first connection string, but when i insert a correct one, i land on an exception as soon as the code tries to create a context.
The underlying provider failed on Open.:
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: TCP Provider, error: 0 - The wait operation timed out.)
In the event viewer it tells me that the user has been authenticated via Authentication Type: Forms , which I assume it means the auth system (the one using ApplicationServices connection string) is working, the stack trace confirms that the error occours when I try to use EF in code, meaning the DB has been used succesfully to check user credentials
note that:
The web app works in other environments
I can connect to the sql server using the credentials via SSMS
I've assigned a local windows account to the app pool that can also access the database, and tried changing to Integrated Security=SSPI
Both .Net 3.5 and .Net 4.8 are installed
The database is on the local machine and has been restored from a dump of the other one, its users have been mapped, and to rule out issues i gave it ample authorisations with dbowner datawriter and datareader
I've been trying to fix this since a couple days checking similar issues on SO with no avail and I don't really know how to proceed, is there something I can do to troubleshoot the issue?
Apologies, I've found out the answer, and it's specific to the code base. Apparently the connection string was being ignored (despite being perfectly usable) in favour of data saved in a table.
Had to contact the previous developer to find out, guess it's a good example of how important is to document your code
I'll close the thread, thanks for all who tried to help
I've just set up a MySQL database in AWS, however every time I try to connect programmatically I get an access denied exception. Connecting through MySQL Workbench works absolutely fine.
I've added my IP address to the Inbound Rules in AWS (without it, Workbench can't connect so it's definitely set up somewhat correctly) and even added a rule to allow all IP addresses for all traffic:
This is a bare minimum example of what I'm trying to do:
using MySql.Data.MySqlClient;
MySqlConnection connection = new(CONNECTION_STRING);
connection.Open();
which throws the exception on connection.Open().
Connection string:
Server=aa11sgbkk911b5j.cevakqici96g.eu-west-2.rds.amazonaws.com;Database=ebdb;Uid=username;Pwd=password;
The exact exception:
MySql.Data.MySqlClient.MySqlException
HResult=0x80004005
Message=Authentication to host 'aa11sgbkk911b5j.cevakqici96g.eu-west-2.rds.amazonaws.com' for user 'username' using method 'mysql_native_password' failed with message: Access denied for user 'burntorangeadmin'#'cpc150000-brnt4-2-0-cust812.5-2.cable.virginm.net' (using password: YES)
Source=MySql.Data
...
Does anyone have any idea why I can't connect?
I originally had the database coupled to an Elastic Beanstalk instance, and after creating a new one separately everything worked as expected.
So still no actual solution to why it wasn't working in the first place, but decoupling has done the trick.
Check that you have granted the appropriate privileges to the user account
Eg.
CREATE USER 'cdcuser'#'%' IDENTIFIED WITH mysql_native_password BY "cdcpwd";
GRANT ALL PRIVILEGES ON *.* TO 'cdcuser'#'%' ;
FLUSH PRIVILEGES;
I'm trying to setup my local nCache development. In my ASP.net code, I'm calling the following:
Cache cache = NCache.InitializeCache("local-test");
However, it is throwing an OperationFailedException:
No server is available to process the request for local-test
Any idea why? The documentation says that this error typically relates to firewall issues, but I'm running this thing locally.
Configuration
In %NCHOME%\config\client.ncconf, the cache is identified:
<cache id="local-test" client-cache-id="" client-cache-syncmode="optimistic" default-readthru-provider="" default-writethru-provider="" load-balance="True">
<server name="My IP address"/>
</cache>
...and config.ncconf has the following definition:
<cache-config name="local-test" inproc="False" config-id="0" last-modified="" type="local-cache" auto-start="False">
<log enabled="True" trace-errors="True" trace-notices="False" trace-warnings="False" trace-debug="False"/>
<perf-counters enabled="True"/>
<compression enabled="False" threshold="100kb"/>
<notifications item-remove="False" item-add="False" item-update="False" cache-clear="False"/>
<cleanup interval="15sec"/>
<storage type="heap" cache-size="250mb"/>
<eviction-policy enabled="True" default-priority="normal" policy="lru" eviction-ratio="5%"/>
</cache-config>
I am listing down some the reasons for this exception to be raised.
• This error is sometimes thrown when the Cache you are trying to connect is stopped on the machine
You can verify this by running the 'Get-Caches' cmdlet from PowerShell. If it is not currently running on this machine, you can start the Cache by using the 'Start-Cache' cmdlet from PowerShell.
PowerShell Guide: http://www.alachisoft.com/resources/docs/ncache/powershell-ref/
• When an application tries to connect to the Cache, the IPs where the Cache is hosted are checked through the Client.ncconf file ("C:\Program Files\NCache\config\client.ncconf"). If the IPs that are mentioned are wrong, your call may go to a completely different server where either cache is not running or service is not accessible at all.
You can review that the IP configured against the Cache in the Client.ncconf is the same as what you have currently running on the box. So for example if your IP is '192.16.1.1' then your Cache's client.ncconf tag should look something like this.
<cache id="mycache" client-cache-id="" client-cache-syncmode="optimistic" default-readthru-provider="" default-writethru-provider="" load-balance="False" enable-client-logs="False" log-level="error">
<server name="192.16.1.1"/></cache>
This IP should be the same as the one that is configured in the NCache Service configuration file.
• If the machine has dual IPs and the NCache Service is running on a different IP (than the one where the Cache is hosted or configured to host) then your application may also get this error.
Please make sure that your NCache Service is currently running on the correct IP as well. Please check the value against the following tags in the NCache Service Configuration file (C:\Program Files\NCache\bin\service\Alachisoft.NCache.Service.exe.config)
<add key="NCacheServer.BindToClusterIP" value=" xx.xx.xx.xx "/>
<add key="NCacheServer.BindToClientServerIP" value="xx.xx.xx.xx"/>
Please make sure that this is the same IP as the one configured in the Client.ncconf file.
• This error could also be thrown in such a scenario where there is a firewall enabled on the machine, it could be denying the access to the ports on which the Cache host process is running. .
Please make sure that the Cache Ports are opened in the Firewall, if the firewall is enabled. You can verify the Cache's Port from this file "C:\Program Files\NCache\bin\service\CacheHostPorts.xml". If this still doesn't work, please disable the firewall completely and check.
I had an old version of the NCache libraries installed. When I upgraded the client DLLs, everything started working.
I keep getting an error when trying to access the database from a web site it returns an error that it can't find the server or it's inaccessible.
Now I did a search and I found many possible reasons - I turned on named pipes and also did what this link suggested (i.e. set the IP addresses to "enabled") yet I'm still getting the error.
Error SqlException: System.Data.SqlClient.SqlException (0x80131904):
Error An error has occurred with the network or the occurrence when
connecting to SQL Server. Can not find server or is not available.
Verify that the instance name is correct and that the configuration of
SQL Server allow remote connections. (provider: Named Pipes Provider,
error: 40 - Could not open a connection to SQL Server) at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) at
I also downloaded this little app and I copy/pasted the connection string from the web.config used in IIS for this site and the app is able to connect and query the same database being targeted by the web site.
And, as the title says, this error is utterly missing when I debug it in VS2010. What could be causing this error when launching from the server?
Edit: the connection string includes a user name and password (it's not Windows Authentication).
Most likely a security issue. If using windows authentication then make sure the thread pool that the web application is running as has sufficient DB access\privileges.
The issue is that the web.config references another config file
<appSettings file="config/dev.config">
and so the connection string in web.config is ignored over the one in dev.config - an error to have it in both (the one on the test server was created by someone else and worked on static pages - it only failed when the website had to query the database), that's why the version in Visual Studio was running fine.
I have built a C# WinForms application which accesses a SQL Server 2008 for data manipulation.
The application works fine on the machine that was developed on. However when I copy the EXEs and move it to another computer (Windows XP), I got the following error during the login to the system (in other words, when i access the database).
Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed
Here's my connection string:
Data Source=vmsql;Integrated Security=SSPI;Initial Catalog=ChequeBookInventory
Stack trace is given in a screen shot
Any idea how to fix this issue?!
Most likely, the program is not executed with full trust. Either because the computer is configured like this or you are running it from a network share...
Some more info can be found here.
Grant the executing user rights to the database.
Well It was a combination of things that did the trick...
Setup code level access... I had allow full trust on machine level that network share URL through .NET Fx configuration (Whc i had to install seperately)
Install .NET latest version.. (I stuck to 3.5 ;-] )
Thanks for all the help guys :-)!!
If you want to connect to SQL Server remotely, and don't want use the username and password but Windows Authentication, that's just one way - "AD" ,I think AD might cause more problems (but AD is more secure), and I am really sorry about that my answer is not correct, I found some references about that issue,I think it might be help.
1.How to troubleshoot the "Cannot generate SSPI context" error message
2.“Cannot Generate SSPI Context” error message, more comments for SQL Server
3.“Cannot generate SSPI context” error message, when connect to local SQL Server outside domain
4.Service Principal Names (Windows)
5."Access Denied" error message when you try to access remote resources
that's bad answer bellow:
If you use "Integrated Security=SSPI", that means you can't connect to SQL Server remotely.
if you want to connect remotely, please use "User Id=myUsername;Password=myPassword;" instead of "Integrated Security=SSPI".
(Of course your SQL Server must accept "remote connection")connection string for connecting to data sources