Whats wrong with my SQL?

Discussion in 'Databases' started by boydteamor1, Mar 5, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi, im doing a simple web in c#, already have the database, and im using the connection string provided in MS SQL 2005 Database Manager at control panel:

    'Data Source=tcp:sql2k516.discountasp.net;Initial Catalog=SQL2005_470256_acc;User ID=SQL2005_470256_acc_user;Password=mypass;'

    but, i have this error:

    System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 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.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) 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 bOYd.log.Functions.LogIn(String socketHandle, String dayHour, String HID, String tipoGB)

    also im trying to load the database from the host, so whats wrong?

    this is the code im using:

    string connectionString = 'Data Source=tcp:sql2k516.discountasp.net;Initial Catalog=SQL2005_470256_acc;User ID=SQL2005_470256_acc_user;Password=mypass;';

    SqlConnection conn = new SqlConnection(connectionString);
    conn.Open();

    please giveme a solution =]
     
  2. With SQL Server you should make the connection in your config files, i.e. root web.config
    Then with one of the data readers load the connection from the config.

    Are you using one of the Visual Studio products?
    If so, there are some very good videos on this over at http://asp.net
    Salute,
    Mark
     
  3. The first thing I see is your trying to force TCP:. Not sure why. Try removing it.
    Other than that I don't see anything wrong.
    I would agree with previous poster that adding the connection to your Web.Config is better (safer and easier) but it shouldn't make a difference in the functioning.

    To add to web.config add the <connectionStrings> section (if it's not already there) and it should look, approximately like:

    <connectionStrings>

    <remove name='LocalSqlServer'/>
    <add name='LocalSqlServer' connectionString='Data Source=sql2k503.discountasp.net;Initial Catalog=SQL2005_XXXXXX_data;Persist Security Info=True;User ID=discount_user_name;Password=xxxxxx' providerName='System.Data.SqlClient'/>

    </connectionStrings>

    Then is you page you can use that connectioon as
    Dim dbConnection As New SqlConnection
    dbConnection.ConnectionString = ConfigurationManager.ConnectionStrings('LocalSqlServer').ConnectionString

    Sorry ... don't remember the C version.

    By the way ... if your using visual studio, the lazy mans way to do this and check the connection is working is the creat a new page, drag a datagrid on and use the wizard to create the data source. Look as you go through it and when it asks if you want to save it as a shared connection say yes ... all the code ends up in web.config.
    Pick simple Select * from SimpleTable and if it produces data without the erroe you know your good to go.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page