Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Saturday, February 25, 2012

Connection string to sql server

Hi I am trying to write the following connection string:

public static SqlConnection connect()
{
SqlConnection sqlConn = new SqlConnection("server=9.0.3042;database=Menu;Connection Lifetime=300");
return sqlConn;
}

I am trying to connect to a sql database using c# code. The code above is in a seperate file.

The code below is the code used to talk to the database

SqlConnection sqlConn = connection.connect();
sqlConn.Open();

SqlCommand menubar = new SqlCommand("Select * from Menu_table", sqlConn);
SqlDataAdapter dataAdapter5 = new SqlDataAdapter();
dataAdapter5.SelectCommand = menubar;
DataSet dataSet5 = new DataSet();
dataAdapter5.Fill(dataSet5);
DataTable selcartest4 = dataSet5.Tables["table"];

However the connection is just timing out like I have the wrong address set for the connection on the first bit of code posted

any heklp would be great

cheers

J

you have to give the NAME of the server not the version for the Server attribute. also you should specify the type of authentication. Referhttp://www.connectionstrings.com/?carrier=sqlserver2005 for some samples..

server=<ServerName>;database=Menu;Connection Lifetime=300

|||

Hi

Thanks for the reply, I have changed the server name to its correct IP address but its stilf ailing and I get the followin g message:

The user is not associated with a trusted SQL Server connection.

I have set it in sql server for both sql and windows authentication

is there any reason for this to happen?

cheers

Jamie

|||

If its not a production server, try restarting the SQL server and see if it helps.

|||

Hi

I have tried re-starting it as its not a production server but still failing, is there something wrong with the firewall settings maybe.

Wehn I use the stadard connection string vwd provides its OK but I wanted to set up a connection string in c#

cheers

Jamie

Friday, February 24, 2012

Connection string for VBEE to SQL 2005

I have SQL 2005 and I wanted to write a little program in Visual Basic 2005 Express Edition (VBEE) to carry out some processes. While away I built my user form, but when I got back I found that VBEE refuses to connect to SQL Server 2005 and is only configured to link to SQL Express.

The data source is set to .\SQLEXPRESS in the advanced properties of the Add Connection form in the Data Source Configuration Wizard and you can not change it.

I read in MSDN ID 329721 that you can create a data layer that will allow you to use the wizards, but that is as far as it went and is above my programming skills.

So my only options are use VB.Net 2003 Standard edition, use connected mode or give up and it was only supposed to be a quick fix. Had anyone else had this same issue and developed a work around?I have entered the following

Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class Form1
Public SQLPubsConnString As String = "Provider=SQLOLEDB;Data Source=TOTALLY-PBN-FS;Integrated Security=SSPI;Initial Catalog=Sword of Destiny Back End_Data.MDF"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cn As New OleDbConnection
cn.ConnectionString = SQLPubsConnString
cn.Open()

End Sub

and I get this error:

Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I have no idea what this mean, I tried to connect to the help files and nothing, any clues would be appreciated|||Quick rant, why did Microsoft not include SQL 2005 within the Add Connection in VBEE, it is totally stupid?|||to connect to sql2005, you can use a connstr like this (assuming windows auth)

server=MYSERVER; database=MYDB; trusted_connection=yes;

many more examples here:
http://www.connectionstrings.com|||Many thanks, I tried it and it asks for a provider, I then enter one and it comes up with the same message. I had already located that excellent site and I have tried various permutations and no joy. I am using Windows Authorization by the way.

Sadly it looks like I will have to continue using my Access MDB front end that keeps getting ODBC timeouts which is not solvable.|||I worked out what it was while lying in bed, and sorted it this morning, it seems that as I had stored the project on a network drive it was tripping on security, as soon as I moved the project to My Documents the connection string worked, doh!!!|||you can store in your web.config



<add key="ConnectionString"
value="Server=(local);Database=yourDataBaseName;User ID=;Password=;Trusted_Connection=True"
/>

the keywords (local) works for localhost|||Thanks for your advice I will remember that as I will be setting up something for the Web, in the end I did this:

Public WithEvents cnn As New SqlConnection
Public SQLPubsConnString As String = "data source=TOTALLY-PBM-FS;Initial Catalog=Sword of Destiny Back End;Integrated Sec

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim SQLGetControlFormData As String
Dim SQLcommand As New SqlCommand

SQLGetControlFormData = "Select ID, [Character Name], Month, Year From dbo.[Control Form]"

cnn.ConnectionString = SQLPubsConnString
cnn.Open()

SQLcommand.Connection = cnn
SQLcommand.CommandText = SQLGetControlFormData

Dim DRControlForm As SqlDataReader = SQLcommand.ExecuteReader

Do While DRControlForm.Read()
Debug.WriteLine(DRControlForm.Item("ID"))
combobox6.
Loop

DRControlForm.Close()
SQLcommand.Dispose()

I can see the data in the immediate window, so its there, my next challenge is to work out how to get the data into the Form. And to do something like this which I Was doing in Access:

' GetUnitIDSQL = "SELECT [Unit Details].ID, [Unit Details].[Unit Name], [Unit Details].[Unit Type], [Unit Details].[Paid By], [Unit Details].Country, " & _
' "[Unit Details].[Province based], [Unit Details].[Training Level], [Unit Details].[Location], [Unit Details].[Wages PM] " & _
' "FROM [Unit Details] " & _
' "WHERE ((([Unit Details].[ID])=" & UNitID & ") AND (([Unit Details].[Unit Type])=" & "'" & UnitType & "'" & ") " & _
' "AND (([Unit Details].[Paid By])=" & CharID & ") AND (([Unit Details].Country)=" & "'" & Country & "'" & ") AND (([Unit Details].[Province based])=" & "'" & Province & "'" & "));"

' qdf2 = db.CreateQueryDef("Hewitt5734", GetUnitIDSQL)
' rs2 = db.OpenRecordset("Hewitt5734", Type:=dbOpenSnapshot)

' With rs2
' CountB = .RecordCount
' If CountB = 1 Then

' UnitName = .Fields("Unit Name")
' WagesPM = .Fields("Wages PM")
' StartSector = .Fields("Location")

' End If

' End With

' 'db.OpenRecordset("Hewitt5734").Close

' db.QueryDefs.Delete("Hewitt5734")

I do not intend to change any data I bring into the form, I want to use an Update SQL Query at the end to add new records in another table and update certain related records in another Table. As I can't use disconnected mode with this which is with the Wizards working of course then I have to use connected mode.

Tuesday, February 14, 2012

connection string

my web site is in a host. my mssql db is in other host. how I write the connection string. Please help.

You should bookmark this page:http://www.connectionstrings.com/

Now you will never have to ask about a connection string again Big Smile

|||

<

configuration><connectionStrings>

<

addname="connectionName"connectionString="Data Source=ServerName;Initial Catalog=DBName;
User ID=userName;Password=p@.ssw0rd;Persist Security Info=True;"providerName="System.Data.SqlClient"/>

</

connectionStrings>

HTH

|||

JRICE:

<configuration>

<connectionStrings>

<addname="connectionName"connectionString="Data Source=ServerName;Initial Catalog=DBName;
User ID=userName;Password=p@.ssw0rd;Persist Security Info=True;"providerName="System.Data.SqlClient"/>

</connectionStrings>

My understanding of the original question is that the poster wants to connect to a remote instance of SQL Server.

|||

Mikesdotnetting:

JRICE:

<configuration>

<connectionStrings>

<addname="connectionName"connectionString="Data Source=ServerName;Initial Catalog=DBName;
User ID=userName;Password=p@.ssw0rd;Persist Security Info=True;"providerName="System.Data.SqlClient"/>

</connectionStrings>

My understanding of the original question is that the poster wants to connect to a remote instance of SQL Server.

in theData Source=ServerName .. place you database server ip with the port ... e.g if your server is in 192.168.2.100 ... and sql port is 9989 then use

Data Source=192.168.2.100,9989 ......

hope it helps you..

|||Thanks for your helping.|||Thank U too.

Connection String

Can I write the connection string that uses a specific Windows user account
and not SQL user account?Hi
You can't.
NT Integrated security uses the context of the logged on user/service to
pass to the SQL Server. You can not change that.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Yuliaan" <Yuliaan@.discussions.microsoft.com> wrote in message
news:B1982B11-48CF-4E91-BC13-554982AD8E41@.microsoft.com...
> Can I write the connection string that uses a specific Windows user
> account
> and not SQL user account?

Connection String

Can I write the connection string that uses a specific Windows user account
and not SQL user account?
Hi
You can't.
NT Integrated security uses the context of the logged on user/service to
pass to the SQL Server. You can not change that.
Regards
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Yuliaan" <Yuliaan@.discussions.microsoft.com> wrote in message
news:B1982B11-48CF-4E91-BC13-554982AD8E41@.microsoft.com...
> Can I write the connection string that uses a specific Windows user
> account
> and not SQL user account?

connection stiring for MSDE

Dear All,
I tried to write the connection string for MSDE in JSP, but I had no luck
with it.
Is there anyone solved this problem?
Thank you..
The following link is a good resource for connection strings of all
flavors:
http://able-consulting.com/ADO_Conn.htm
--Mary
On Thu, 23 Sep 2004 09:58:21 +0200, "Loay Olabi"
<big_faceNO-SPAM@.lycos.coom> wrote:

>Dear All,
>I tried to write the connection string for MSDE in JSP, but I had no luck
>with it.
>Is there anyone solved this problem?
>Thank you..
>

Friday, February 10, 2012

Connection Problem when Installed SQL Ser 2000 & SQL Server 2005

Hi All!

In my computer I have Installed MS SQL Server 2005(Default Instance) & MS SQL Server 2000(Duynnh Instance). When I write an ASP.NET app to connect to SQL Server 2005 it's OK but not connect in SQL Server 2000. Please give me the SQL Connection string to connect to SQL Server 2000.

When I open Query analyzer connection is OK for both.

Thanks.

This is an awesome site i use to get connection string formats

http://www.connectionstrings.com/

Another easy way to get connection strings is to drag and drop and data adapter or a table from a database in server explorer, and look at the connection string it builds.

|||

I think sql2000 and sql2005 use the same kind of connection string--both use the same sql server provider. You only need to check if you have specified the correct instance name, default database, login account/psw (if you use sql authentication mode) in your sql2000 connection string.

Hope my suggestion helps