ASP.NET C# Connect to MySQL

0

Szukam sposobu
połączenia się z bazą danych MySQL z C# w ASP.NET ale z bazą danych po stronie serwera ... Nie lokalną zainstalowaną na komputerze .

Jak to zrobić ? Moje próby kończą się różnymi błędami, a połączenia brak.

Mam serwer na ASP.NET

1

Musisz stworzyć connectionString, i podać podstawowe parametry tj. adres bazdy danych, login hasło itp, oraz dodać bibliotekę do aplikacji do bazy MySql.

0

gdzie masz tą bazę?

0

Jak wrzucę na hosting moją stronke to dostaję takie cuda :


ZWRACA mi takie cuda : 

The system cannot find the file specified 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[Win32Exception (0x80004005): The system cannot find the file specified] 

[SqlException (0x80131904): 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)] 
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +92 
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +285 
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, SqlAuthenticationMethod authType) +372 
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +172 
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +818 
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +320 
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken) +591 
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +304 
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38 
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +681 
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +89 
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +426 
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78 
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +191 
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154 
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21 
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90 
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +166 
System.Data.SqlClient.SqlConnection.Open() +96 
Dziennik2.WebForm2.BindData() in c:\Users\admin\Documents\Visual Studio 2012\Projects\Dziennik2\Oceny.aspx.cs:22 
Dziennik2.WebForm2.Page_Load(Object sender, EventArgs e) in c:\Users\admin\Documents\Visual Studio 2012\Projects\Dziennik2\Oceny.aspx.cs:16 
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 
System.Web.UI.Control.OnLoad(EventArgs e) +95 
System.Web.UI.Control.LoadRecursive() +59 
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678
0

a masz dostęp do bazy ze zdalnego kompa?? Bo jeśli to darmowy hosting to szczerze wątpię

0

ale ten log co wysłałem jest po stronie serwera wrzuciłem projekt na serwer i kaput ... nie włącza się strona a dostaję te informacje które wstawiłem wyżej. I co z tym można zrobić ? Ja chce korzystać z SQL z poziomu serwera (plików które mam na FTP) ... a nie na moim kompie ....

0

może byś podał np. connection stringa. BTW w pytaniu masz MySQL a w błędzie masz MSSQL - widzisz drobną różnicę?

0

Ja nie wiem skąd ona wynika, bo na serwerze zrobiłem tabele w MySQL jest tam również MSSQL ...

Connection string ma budowę: "Server=MYSQL5012.myASP.NET;Database=db_9df278_ms;Uid=9df278_ms;Pwd=YOUR_DB_PASSWORD;"

I jest generowany przez SERWER ....
Oczywiście w miejsce hasła, wpisuję moje hasło.

Link do strony (serwera) podać ? .

0

Pokaż web.config. Wygląda to tak jakbyś miał tam wpisane dwa ConnectionStringi i używał nie tego co trzeba w aplikacji.

0
<?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.5" />
      <httpRuntime targetFramework="4.5" />
      <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
      <customErrors mode="Off" />
     
    </system.web>
</configuration>
0

Nie ten web.config tylko ten zawierający connection string.

0

Nie mam connect stringa w web.config

Mam wpisanego go w nazwaPodStrony.cs

public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
protected void BindData()
{

        MySqlConnection con = new MySqlConnection("server=MYSQL5012.myASP.NET; database=db_9df278_ms; uid=9df278_ms; pwd=mojeHaslo");
        MySqlCommand cmd = new  MySqlCommand("select * from oceny", con);
        DataSet ds = new DataSet();
        MySqlDataAdapter da = new  MySqlDataAdapter(cmd);
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }

    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
       // GridView1.PageIndex = e.NewPageIndex;
        BindData();
    }

     
    }
}

Przy okazji, nie da się używać e.NewPageIndex a na każdym tutki z GridView z niego korzystają :D

1 użytkowników online, w tym zalogowanych: 0, gości: 1