1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / using a own table from database?

using a own table from database?

2 posts, 0 answered
  1. Magnus
    Magnus avatar
    28 posts
    Registered:
    26 May 2009
    02 Nov 2009
    Link to this post
    Hi.

    I've got a problem using a own table (with a own connection, using the ConfigurationManager.ConnectionStrings["Sitefinity"].ConnectionString;).

    Problem: i cant connect to the same database using the same connectionstring in MySQL. I've done the same thing using MSSQL and didnt have any problem at all.

    I'm trying to get/update/delete data from that table from a SQLConnection/SQLDataAdapter the "old way".

    Eg.

    try 
            { 
     
             string ConnectionString = ConfigurationManager.ConnectionStrings["Sitefinity"].ConnectionString; 
              
                string query = "SELECT * FROM sq_Guestbook "
                if (p_sOrderby != "") 
                { 
                    query += "ORDER BY @p_sOrderby "; 
                } 
                if (p_sAmount != "" && p_sStart != "") 
                { 
                    query += "LIMIT @p_sStart , @p_sAmount "; 
                } 
     
                DataTable dt = new DataTable(); 
     
                using (var conn = new SqlConnection(ConnectionString)) 
                { 
                    using (var da = new SqlDataAdapter(query, conn)) 
                    { 
                        if (p_sOrderby != "") 
                        { 
                            da.SelectCommand.Parameters.AddWithValue("@p_sOrderby", p_sOrderby); 
                        } 
                        if (p_sAmount != "" && p_sStart != "") 
                        { 
                            da.SelectCommand.Parameters.AddWithValue("@p_sStart", p_sStart); 
                            da.SelectCommand.Parameters.AddWithValue("@p_sAmount", p_sAmount); 
                        } 
     
                        da.Fill(dt); 
                    } 
                } 
     
         return dt; 
            } 
            catch (Exception ex) 
            { 
                System.Web.HttpContext.Current.Response.Write(ex); 
                return null; 
            } 


    And all i end up with is this errormessage:

    "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) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) 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 dbGuestbook.GetPosts(String p_sOrderby, String p_sAmount, String p_sStart) in c:\inetpub\wwwroot\vdk\App_Code\dbGuestbook.cs:line 130"



    Do i need to close the connection with the database before i use my own SQLConnection? and if so? How do i do that? I've tried the same code with an MSSQL database without any problems at all.

    Thanks for any help.


    Kind Regards / Magnus.
  2. Magnus
    Magnus avatar
    28 posts
    Registered:
    26 May 2009
    02 Nov 2009
    Link to this post
    Please. Dont remind this post.

    You cannot use SqlDataClient with MySQL (without installing it on the server). My bad.


2 posts, 0 answered