Connecting to remote server - c#

I have a windows server on domainindia.org. I have created one user for mysql and I am trying to connect to MySQL using the following connection string in c#.
Driver={MySQL ODBC 3.51 Driver};Server=IPaddress;Database=db1;User=user;Password=password; Option=3;
I am unable to connect. Can someone tell me what may be the problem in this connection string?
The same connection string is working in my local.
I tried to grant permission for that but does not allows me to execute the query.
Can any one tell me how can I connect to my server?
Here is my web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="dbConnection" connectionString= "Driver={MySQL ODBC 3.51 Driver};Server=IPadress;Database=db1;User=Myuser;Password=myPassword;Option=3;"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>

Related

How to make a connectionString to connect ado.net c# to on virtualmachine running SQL Server

I'm having some difficulties to connect to SQL Server running on a virtual machine (virtualbox). I'm using ADO.NET in C# to do the connection through a connection string but I'm not having any success with this.
My app.config file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<connectionStrings>
<add name="AP3"
connectionString="Data Source=190.166.2.8,1433;Initial Catalog=AP3;
User Id=sa;Password=PasswOrd;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
I don't know if I'm doing anything wrong...
It seems that you've not allowed Sql Server for Remote Connections. Kindly follow this link for more details
You can add DBMSSOCN to use TCP/IP instead of Named Pipes.Maybe it is a problem.
try this connection string.
"Data Source=190.166.2.8,1433;Network Library=DBMSSOCN;Initial Catalog=AP3; User Id=sa;Password=PasswOrd;"

VS 2010 Connecting to SQL Server 2008: Login failed for user "

I've created a web forms project in Visual studio 2010 that has to connect to an SQL Server 2008 database that's located on a different computer on the local network.
Here's my connection string from the web.config file:
<connectionStrings>
<add name="myDatabase"
connectionString="Data Source=myDatabase;Initial Catalog=myCatalog;Persist Security Info=True;User ID=sa;Password=myPassword*"
providerName="System.Data.SqlClient" />
</connectionStrings>
And here's the string used in my entlib.config file:
<configuration>
<configSections>
<section name="dataConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<dataConfiguration defaultDatabase="myDatabase" />
<connectionStrings>
<add name="myDatabase"
connectionString="Data Source=myDataBase;Initial Catalog=myCatalog;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
The problem I'm encountering changes based on what's in entlib.config. If
Integrated Security=true;
is in the connection string the error I get is
Login failed. The login is from an untrusted domain and cannot be used
with Windows authentication.
And if the integrated security tag is removed I get
Login failed for user ''.
I don't know why this isn't working because my company has other web projects that are able to connect to this database and I'm using the same exact connection code. The user name and passwords work when I log into SQL Management Studio. I can see the database in VS 2010's server explorer, and I'm using the connection string from there. I'm passing SQL Server authentication, and I know the right server is being reached.
Try copying the entire connectionString value from web.config to entlib.config

Encryption web.config file "aspnet_regiis.exe" not working

I work with asp.net fromwork 4.0 web site. and I want to encrypt web.config file connectionString. I used aspnet_regiis -pef "connectionString" "file Location"
but it's not working. Rather I'm getting only the error message as shown below
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
</system.web>
<connectionStrings>
<add name="MS_EAS_LocationConnectionString" connectionString="Data Source=help\sqlexpress;Initial Catalog=MS.EAS.LOCATION;User ID=sa;Password=123" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>

Deploying Microsoft ASP.NET application

I am trying to deploy an Microsoft ASP.NET application over to a hosting provider. I don't think I am able to configure the IIS server or anything like that.I have managed to upload my files to the server through FTP but I am facing the error:
"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."
I am able to access the databases of the domain but I am not sure what configurations to use especially for my web.config. I am using an mdf file
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="DBConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Details.mdf;Integrated Security=True;User Instance=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.0">
</compilation>
<authentication mode="Forms">
<forms timeout="50"/>
</authentication>
<sessionState cookieless="true" regenerateExpiredSessionId="true" mode="InProc" timeout="60" />
<httpRuntime executionTimeout="180" requestValidationMode="2.0" requestPathInvalidCharacters="" maxRequestLength="1048576" />
</system.web>
</configuration>
It looks like your application is using SqlExpress to work with a local (to your project) database. Two things to look for - first, did the MDF absolutely make it to your deployed location? Sometimes things in App_Data are left behind during a publish. The other thing to check is whether the hosting provider to which you've deployed supports SQL Express and that the Data Source in your connection string is the proper way to utilize it on that platform.

connection string issue in web.config of ASP.Net

I am using VSTS 2010 + C# + .Net 4.0 to develop an ASP.Net application using SQL Server 2008 Enterprise as database. I am learning someone else's code. I notice code like this, I am not sure whether the usage is correct and so I come here to ask for advice.
In the code, I see some code like this, I want to know whether using such method to read connection string from web.config is correct?
ConfigurationManager.ConnectionStrings["DBConnectinString"].ConnectionString
and such code is used to read connection string from web.config like below, please notice that connection string is defined outside of system.web section.
<?xml version="1.0"?>
<configuration>
<configSections>
<!--this section is empty-->
</configSections>
<appSettings>
...... content of appSettings
</appSettings>
<connectionStrings>
<add name="DBConnectinString" connectionString="data Source=.;uid=foo;pwd=foo;database=FOODB" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
... ... content of system.web
</system.web>
</configuration>
That is the standard place to define connection strings in web.config, yes.
See this for more info: http://msdn.microsoft.com/en-us/library/ms178411.aspx

Categories