Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

asp.net + ms sql

asp.net

  • Please log in to reply
11 replies to this topic

#1 nikodz

nikodz

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 10 February 2011 - 11:06 AM

hello.
I want to connect MS SQL with asp.net framework 2.0

using Windows 7, IIS 7.0, Visual Studio 2010. Also using programming language C#.

Thanks.
  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 10 February 2011 - 10:34 PM

There appears to be a nice tutorial here:
Connecting to MSSQL Server in ASP.NET

I am sure there is great documentation on Microsoft's MSDN network.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#3 nikodz

nikodz

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 11 February 2011 - 12:48 AM

Alexandre
Thanks.

Here I learn how to connect MS SQL Server, do you know how to connect mdf (*.mdf) file?
I think I have problem with connection string.
  • 0

#4 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 11 February 2011 - 02:12 AM

What does yours look like? It may be something like this that should work:
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
There are some more connection string examples here:
SQL Server 2008 Connection String Samples - ConnectionStrings.com
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#5 nikodz

nikodz

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 11 February 2011 - 02:48 AM

I want to connect MS SQL.
Line 17:         SqlConnection con = new SqlConnection("Server=.\\SQLExpress;AttachDbFilename=|DataDirectory|Database.mdf;Database=Users; Trusted_Connection=Yes;");
Line 18:         con.Open();
Line 19:         con.Close();
Error on line 18

Also, cant connect SQL Server 2005 :|
  • 0

#6 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 13 February 2011 - 08:57 PM

Hmm could you copy the exception message and paste it in here, wrap the above code in try catch in catch block publish the message so that you can copy it
  • 0

#7 nikodz

nikodz

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 14 February 2011 - 05:58 AM

private void asd(){
SqlConnection con = new SqlConnection("Data Source = Niko-PC\\Niko;Initial Catalog = master; Integrated Security = true;");
try{
con.Open();
con.Close();
}
catch(Exception e){
loutput.Text = e.ToString();
}
}

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: 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.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 _Default.asd() in d:\IIS\Start\www\Default.aspx.cs:line 28


......
  • 0

#8 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 14 February 2011 - 06:32 AM

ok just a few questions,
What is the instance name of SqlExpress that you are running,
Is it Niko? If yes i also want you to do this,
Open the Service Manager Start + Run = services.msc and hit enter
Go to Sql server browser and start the service. Set it to automatic.
Now try again
  • 0

#9 nikodz

nikodz

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 14 February 2011 - 06:48 AM

gokuajmes
Thanks! instance name is SqlExpress ... That was reason.

Thanks again.
  • 0

#10 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 14 February 2011 - 06:50 AM

You are welcome have a happy day
  • 0

#11 nikodz

nikodz

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 14 February 2011 - 11:46 AM

I connected to Sql Server, but now I need to allow new Database (which I made).
  • 0

#12 nikodz

nikodz

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 15 February 2011 - 01:46 AM

I did it.
  • 0





Also tagged with one or more of these keywords: asp.net

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download