|
This is VB forum, please post this question in the Database forum.
|
|
|
|
|
It'll be logging in on your first computer using Windows Authentication. Has the sa-account been enabled? Does the second PC have the correct password?
Bastard Programmer from Hell
|
|
|
|
|
You cannot use a database file on the local machine when connecting to a remote SQL Server instance.
You have to switch to a non-user-instance config string and permanently attach the database file on the remote machine to the SQL Server instance on the remote machine. This is easiesst done using the SQL Server Management tool. Then you can change the Initial Catalog option in your connection string to the database name you assign on the SQL Server.
If you're going to be using Integrated Security, do not supply a username and password. If you have to supply a username and password, do not use Integrated Security. The two options are mutually exclusive.
|
|
|
|
|
Hello,
I changed my connection string to
DBConn.ConnectionString = "Provider=SQLNCLI;AttachDBFileName=" & App.Path & "\newdb.mdf;Database=newdb;User Instance=true;Trusted_connection=Yes;"
but it gives me run time error like
Invalid connection string attribute..
Can you please suggest which attribute is invalid.
Thank You.
modified on Sunday, July 31, 2011 12:28 PM
|
|
|
|
|
How many times have you asked this question?
You don't have a clue what you're doing, do you?
You haven't understood any of the things I said in my other post and know nothing of what's in the connection string. Your "second" attempt you posted contains none of the fixes I told you about and you're still trying to attach a remote instance of SQL Server to a local file, which will not work.
http://www.connectionstrings.com[^]
|
|
|
|
|
|
thatraja wrote: Looks like you have posted this question multiple times
And you still keep answering him each time?
|
|
|
|
|
No, only 2nd time
|
|
|
|
|
Can I use MS Windows theme as GUI in my project?
|
|
|
|
|
Why would you want to?
Better to have your own gui, much more professional.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Hi,
I need to plot a graph(bar charts) on windows form using values from a closed excel sheet .. tried but unable to do so .. can someone plz help me with a small example of how to implement using Zedgraph or any other suitable package ..
Regards...
Gauti..
|
|
|
|
|
|
|
|
Hello All,
Could anyone please let me know, if we have any library or any easy going way, in order to work with USB2 flashdrive... All I need to do is detect a USB2 flash-drive, and then save a file in it.
I am looking for any driver, or library or any other way, So that I dont have to go deeper inside USB protocol.
I can use VB.NET or c# if necessary.
thanks in advance
Hrishi
|
|
|
|
|
Have you looked at this article[^]?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Hello,
So I have some code to change the color of a cell on a datagridview.
If e.Value.ToString.Length > 0 Then<br />
e.CellStyle.BackColor = Color.Blue<br />
e.CellStyle.ForeColor = Color.White<br />
End If
Where is the best place to put this, cell formatting or cell painting. Or is there a better place?
Thanks!
Rudy
|
|
|
|
|
|
Cellformatting is where you want it.
You were close. Just add another line under your code to change the color:
e.FormattingApplied = True
|
|
|
|
|
Hello,
I am currently trying to sort on a GridView after it has been populated with records from a SQL Server Express database.
I click on a column to sort it and I get the following error:
"DataTable must be set prior to using DataView."
The entirety of my code is as follows:
<script runat="server" >
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlClient.SqlCommand
Dim sqlReader As SqlDataReader
'If no values are supplied in the textbox, throw an error message.
If TextBox2.Text = "" Then
MsgBox("A centre code needs to be provided...")
End If
If TextBox2.Text <> "" Then
'Telling the system the location of the database.
sqlConn.ConnectionString = "server=ServerName;Initial Catalog=dbName;Trusted_Connection=yes"
'Here we are opening the connection to the database.
sqlConn.Open()
'This is to say that sqlCmd is a stored procedure.
sqlCmd.CommandType = System.Data.CommandType.StoredProcedure
'This is creating the command to execute the stored procedure based on the information given in the connection string.
sqlCmd = sqlConn.CreateCommand
'The command is triggered to execute the stored procedure which grabs all information for the specific centre.
sqlCmd.CommandText = "exec ProcedureName'" & TextBox2.Text & "' "
'This will read the rows in the database.
sqlReader = sqlCmd.ExecuteReader()
'If there are rows of data that match are criteria
If (sqlReader.HasRows) Then
'The rows of data are grabbed for the specific centre from the database using the data reader.
GridView2.DataSource = sqlReader
GridView2.DataBind()
Else
MsgBox("The centre code provided does not exist...")
End If
'This is closing the connection to the database once we have finished with it.
sqlConn.Close()
'This is to clear the list of items out of the GridView box.
End If
End Sub
Protected Sub gvSorting_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
Dim dtSortView As New DataTable
dtSortView = GridView2.DataSource
If dtSortView Is Nothing Then
Dim dvSortedView As New DataView(dtSortView)
dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection)
GridView2.DataSource = dvSortedView
GridView2.DataBind()
End If
End Sub
Public Function getSortDirectionString(ByVal SortDirection As SortDirection) As String
Dim newSortDirection As String = String.Empty
If (SortDirection = SortDirection.Ascending) Then
newSortDirection = "ASC"
Else
newSortDirection = "DESC"
'Return newSortDirection
End If
Return newSortDirection
End Function
</script>
If anybody can give me any hints and tips on why this is happening, I would be extremely grateful.
From my understanding its telling me that there is no records in the GridView to sort, but why?
Thanks in advance,
Dan
|
|
|
|
|
The problem is, you set the DataSource to a DataReader and trying to cast it back to a DataTable . Use a DataTable as the DataSource for the GridView and your code should work.
|
|
|
|
|
Instead of using, sqlReader = sqlCmd.ExecuteReader()
Use this:
Dim DA As SQLDataAdapter
DA = New SqlDataAdapter(SQLcmd)
DA.Fill(DT)
Gridview2.Datasource = DT
When you use a dataadapter to "Fill" a datatable, it will fetch all the rows into the datatable, so you must be careful that you are not fetching thousands of rows of data, your memory and performance will suffer tremendously.
With the above changes, your grid should sort when you click on a column heading.
david
|
|
|
|
|
Hello David,
Thank you very much.
Quick question though - what is DT?
Is that DataTable?
Thanks,
Dan
|
|
|
|
|
Oops. I forgot to declare the datatable.
<br />
Dim DA As SQLDataAdapter<br />
Dim DT As New DataTable ' I forgot this line before<br />
<br />
DA = New SqlDataAdapter(SQLcmd)<br />
DA.Fill(DT)<br />
<br />
Gridview2.Datasource = DT<br />
<br />
Give me a vote of 5 if this works for you. 
|
|
|
|
|
 Hello David,
I have made the changes you suggested, but am still getting the same error:
Here is the code now:
<script runat="server" >
Public Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlClient.SqlCommand
'Dim sqlReader As SqlDataReader
Dim sqlAdapter As New SqlDataAdapter
Dim sqlDataTable As New DataTable
'If no values are supplied in the textbox, throw an error message.
If TextBox2.Text = "" Then
MsgBox("A centre code needs to be provided...")
End If
If TextBox2.Text <> "" Then
'Telling the system the location of the database.
sqlConn.ConnectionString = "server=ServerName;Initial Catalog=dbName;Trusted_Connection=yes"
'Here we are opening the connection to the database.
sqlConn.Open()
'This is to say that sqlCmd is a stored procedure.
sqlCmd.CommandType = System.Data.CommandType.StoredProcedure
'This is creating the command to execute the stored procedure based on the information given in the connection string.
sqlCmd = sqlConn.CreateCommand
'The command is triggered to execute the stored procedure which grabs all information for the specific centre.
sqlCmd.CommandText = "exec ProcedureName'" & TextBox2.Text & "' "
'This will read the rows in the database.
'sqlReader = sqlCmd.ExecuteReader()
'If there are rows of data that match are criteria
'If (sqlReader.HasRows) Then
'The rows of data are grabbed for the specific centre from the database using the data reader.
'GridView2.DataSource = sqlReader
'GridView2.DataBind()
sqlAdapter = New SqlDataAdapter(sqlCmd)
sqlAdapter.Fill(sqlDataTable)
GridView2.DataSource = sqlDataTable
GridView2.DataBind()
Else
MsgBox("The centre code provided does not exist...")
'End If
'This is closing the connection to the database once we have finished with it.
'sqlConn.Close()
End If
End Sub
Public Sub gvSorting_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
Dim dt = TryCast(Session("TaskTable"), DataTable)
Dim dtSortView As New DataTable
dtSortView = GridView2.DataSource
If dtSortView Is Nothing Then
Dim dvSortedView As New DataView(dtSortView)
dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection)
GridView2.DataSource = dvSortedView
GridView2.DataBind()
End If
End Sub
Public Function getSortDirectionString(ByVal SortDirection As SortDirection) As String
Dim newSortDirection As String = String.Empty
If (SortDirection = SortDirection.Ascending) Then
newSortDirection = "ASC"
Else
newSortDirection = "DESC"
'Return newSortDirection
End If
Return newSortDirection
End Function
</script>
Any ideas at all?
Is there code still in there that needs to be taken out?
Or have I missed a bit of code?
Thanks for your help,
Dan
|
|
|
|