Jump to content
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;using System.Data.SqlClient;[WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService]public class Service : System.Web.Services.WebService{        public Service () {        //Uncomment the following line if using designed components         //InitializeComponent();     }    [WebMethod]    public string TestConnection() {        string retrn;        SqlConnection myConnection = new SqlConnection("user id=root;" +                                       "password=;server=localhost;"+                                       "database=Playlist; " +                                       "connection timeout=10");        try        {            myConnection.Open();            retrn = "conneced";        }catch(Exception ex)        {            retrn = "failed with " + ex;        }        return retrn;    }}

Returns 

 

 

<string xmlns="http://tempuri.org/">

failed with System.Data.SqlClient.SqlException: 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 Server) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at Service.TestConnection() in d:\Aaron\Documents\Visual Studio 2015\WebSites\PlaylistServer\App_Code\Service.cs:line 33
</string>

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/476686-c-connection-to-mysql-server/
Share on other sites

Link to post
Share on other sites

Have you tried reading the error message?

yup dosn't help. "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"

 

It is accessible via phpmyadmin, website I am creating on the PC. Shouldn't need remote connections when it's on my computer

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

You are using the incorrect connection object completely... What you need is the MySql driver, go to NuGet and add it to your project and then try again with that. Did you do a search and look at some of the example code for doing this?

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

You are using the incorrect connection object completely... What you need is the MySql driver, go to NuGet and add it to your project and then try again with that. Did you do a search and look at some of the example code for doing this?

been following this tut

 

http://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

 

Ok but you have eluded that you are trying to use MySql?

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

Ok but you have eluded that you are trying to use MySql?

yeah it's been a  late night -.- i am unsure if SQL is installed in my uni so i was running a portable version of xmapp.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

yeah it's been a  late night -.- i am unsure if SQL is installed in my uni so i was running a portable version of xmapp.

 

Don't worry I know how it goes  :lol:

 

Yeah all of that should be fine; just using the correct driver of course :P Also, as I said before, once you get it working you may want to layer in a framework like EF or NHibernate because it really will make your life easier plus I bet it will score you extra points.

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

Don't worry I know how it goes  :lol:

 

Yeah all of that should be fine; just using the correct driver of course :P Also, as I said before, once you get it working you may want to layer in a framework like EF or NHibernate because it really will make your life easier plus I bet it will score you extra points.

Yeah this feels so over my head.

 

edit:

 

downloaded mysql.data.dll and added as a reference and i now have 

 

<string xmlns="http://tempuri.org/">connected</string>

 

thanks for the help all

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×