Showing posts with label sql-server. Show all posts
Showing posts with label sql-server. Show all posts

Sunday, March 11, 2012

Connection to Sql-Server

Hi,

I'm a newbie at the asp.net site.
The things i have done where with access.
But now i want to use Sql-server

In access i used this to execute a query:

*** In the global.asax ***
session("dbpath") = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" + Server.MapPath("\db\MediaProject.mdb")

*** Return dataSet ***
ResultDS = GetSql(SqlStatement, session("dbpath"))
Dim ResultDS AS system.data.dataset

*** Lib file: ***
Function GetSQL(a As string, b as string) As System.Data.DataSet
Dim connectionString As String = b
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
Dim queryString As String = a
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

The question now is wich string do i now have to put in the session("dbpath") ?
Which is the Provider?
How does the string looks like.
Or do i use something else now ?

Many thanx in advance


oSQLConn.ConnectionString = "Data Source=xxx.xxx.xxx.xxx,1433;" & _
"Initial Catalog=mySQLServerDBName;" & _
"User ID=myUsername;" & _
"Password=myPassword"

Connection To SQL Server 2005 / 2000

Hi everybody,
I got a bit of a problem with my connection. I wrote a programm in VB.Net wich connects to a sql-server 2005. On my local Computer everything works great, but on another Computer in the Network, I just receving timeouts. I allready check, if the sever allows remote connection.
My connectionstring for the SQL connection looks like this:

"Initial Catalog=Bauvorhaben;Data Source=P4-2400\SQLEXPRESS;Password=?;Persist Security Info=True;User ID=Lars"

I allready tried to get an connection to SQL-Server 2000. But the same here.

Does somebody have a clue, why I can't connect?

Thanks,
Lars

By default SQLExpress do not allow remote conneciton.

You need to

1. Turn on remote connection using SQL Server configuration Manager.

2. Start sqlbrowser service that is collocated with the SQLExpress server. SQL Browser service is needed if the sqlserver is a name instance, such as sqlexpress.

3. Make sure you make exception for sqlservr.exe in the firewall configuration of windows.

http://blogs.msdn.com/sql_protocols/archive/2005/11/14/492616.aspx