|
I think you forgot to post your question or script sample. I don't see it.
|
|
|
|
|
I need to connect to a client't SQL Server remotely. They want to set up a VPN for me to minimize security concerns.
Can I access SQL remotely on their network from my office if they set me up a VPN?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
So long as the VPN's connected, it should be the same as accessing a server on the same network.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have been trying forever to set up access to SQL Server on my home server.
I again followed all of the instructions here:
https://medium.com/developer-diary/how-to-enable-remote-connections-to-sql-server-dc5b6c812b5
Windows Firewall is off.
When I try to connect remotely I get
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)
This message mentions 'Named Pipes'. Named pipes is enabled, although from what I can see, Named Pipes are for inter-process communication to occur among processes running on the same machine, so I'm not sure what this is part of the error.
At this point I'm out of options. I've tried eveything I can think of. What could possibly be wrong here??
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
What do you mean by "remotely"? Something else on the same LAN, or something outside of your network?
Check which client protocols are enabled on the computer that's trying to connect. If it doesn't have the SQL configuration tools installed, you'll need to run cliconfg.exe from both C:\Windows\System32\ (64-bit) and C:\Windows\SysWow64\ (32-bit).
Also check your connection string to make sure you're using the correct server and instance name. For example, ".\SQLEXPRESS" won't work from a remote computer.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Remote from my office to my home server. I connect using my IP addrss.
Richard Deeming wrote: Check which client protocols are enabled on the computer that's trying to connect. If it doesn't have the SQL configuration tools installed, you'll need to run cliconfg.exe from both C:\Windows\System32\ (64-bit) and C:\Windows\SysWow64\ (32-bit).
Well, that did it!!!
Wow, I've been trying on & off again for MONTHS to get this to work. THANK YOU!!
I've set up SQL Remote access before, and I don't remember ever having use 'cliconfg.exe' before. Is this documented somewhere?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I can't see an MS documentation, but there are various blogs describing the tool - for example:
How to setup and use a SQL Server alias[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Awesome, thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Kevin Marois wrote: I take all this back. As soon as I posted I thought, I'll give it one more try - and it connected
Isn't that always the way it goes?
Glad you got it sorted.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi all,
When I exporting Database table to Excel my date fields are giving 23/01/1990 00:00:00 in stat of 23/01/1990
Please can some one help me in the right way.
Quote: protected DataTable ExportDataFromSQLServer()
{
DataTable dataTable = new DataTable();
using (SqlConnection connection = new SqlConnection(@"Data Source= 127.0.0.1\MSSQLSERVERJAN; Initial Catalog=BHV; User ID=sa;Password=XXXXXXX"))
{
connection.Open();
// Define the query to be performed to export desired data
SqlCommand command = new SqlCommand("select * from BHVUsers", connection);
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
dataAdapter.Fill(dataTable);
var excelApplication = new Excel.Application();
var excelWorkBook = excelApplication.Application.Workbooks.Add(Type.Missing);
DataColumnCollection dataColumnCollection = dataTable.Columns;
for (int i = 1; i <= dataTable.Rows.Count + 1; i++)
{
for (int j = 1; j <= dataTable.Columns.Count; j++)
{
if (i == 1)
excelApplication.Cells[i, j] = dataColumnCollection[j - 1].ToString();
else
excelApplication.Cells[i, j] = dataTable.Rows[i - 2][j - 1].ToString();
}
}
excelApplication.Cells[1, 2] = "Voornaam";
excelApplication.Cells[1, 3] = "Achternaam";
excelApplication.Cells[1, 4] = "Geboorte Datum";
excelApplication.Cells[1, 5] = "Porto nummer";
excelApplication.Cells[1, 6] = "EHBO behaald";
excelApplication.Cells[1, 7] = "EHBO";
excelApplication.Cells[1, 8] = "BHV";
excelApplication.Cells[1, 9] = "Regisseur";
excelApplication.Cells[1, 10] = "Verlopen EHBO";
excelApplication.Cells[1, 11] = "Laatste herhaling EHBO";
excelApplication.Cells[1, 12] = "EHBO nummer";
excelApplication.Cells[1, 13] = "Verdieping";
excelApplication.Cells[1, 14] = "Ruimte";
excelApplication.Cells[1, 15] = "Email";
excelApplication.Cells[1, 16] = "Mobiel";
excelApplication.Cells[1, 17] = "Opmerking";
excelApplication.Cells[1, 18] = "BHV_Behaald";
excelApplication.Cells[1, 19] = "BHV_Verlopen";
excelApplication.Cells[1, 20] = "Laatste_Herhaling_BHV";
excelApplication.Cells[1, 21] = "Ruisnaam";
excelApplication.Cells[1, 22] = "Regisseur_Verlopen";
excelApplication.Cells[1, 23] = "Regisseur_Behaald";
excelApplication.Cells[1, 24] = "Regisseur_Herhaling";
excelApplication.Cells[1, 25] = "Active_no_yes";
excelApplication.Cells[1, 2].Font.Bold = true;
excelApplication.Cells[1, 3].Font.Bold = true;
excelApplication.Cells[1, 4].Font.Bold = true;
excelApplication.Cells[1, 5].Font.Bold = true;
excelApplication.Cells[1, 6].Font.Bold = true;
excelApplication.Cells[1, 7].Font.Bold = true;
excelApplication.Cells[1, 8].Font.Bold = true;
excelApplication.Cells[1, 9].Font.Bold = true;
excelApplication.Cells[1, 10].Font.Bold = true;
excelApplication.Cells[1, 11].Font.Bold = true;
excelApplication.Cells[1, 12].Font.Bold = true;
excelApplication.Cells[1, 13].Font.Bold = true;
excelApplication.Cells[1, 14].Font.Bold = true;
excelApplication.Cells[1, 15].Font.Bold = true;
excelApplication.Cells[1, 16].Font.Bold = true;
excelApplication.Cells[1, 17].Font.Bold = true;
excelApplication.Cells[1, 18].Font.Bold = true;
excelApplication.Cells[1, 19].Font.Bold = true;
excelApplication.Cells[1, 20].Font.Bold = true;
excelApplication.Cells[1, 21].Font.Bold = true;
excelApplication.Cells[1, 22].Font.Bold = true;
excelApplication.Cells[1, 23].Font.Bold = true;
excelApplication.Cells[1, 24].Font.Bold = true;
excelApplication.Cells[1, 25].Font.Bold = true;
int k = 0;
for (k = 1; k <= 23; k++) // this will aply it form col 1 to 10
{
excelApplication.Columns[k].ColumnWidth = 30;
}
Excel.Range formatRange; formatRange = excelApplication.get_Range("a1", "y1");
formatRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightBlue);
//excelApplication.Cells[1,1] = "LightBlue";
formatRange = excelApplication.get_Range("a1", "y1");
formatRange.BorderAround(Excel.XlLineStyle.xlContinuous,
Excel.XlBorderWeight.xlMedium, Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic);
// Save the excel file at specified location
excelApplication.ActiveWorkbook.SaveCopyAs(@"C:\tmp\test1.xlsx");
excelApplication.ActiveWorkbook.Saved = true;
MessageBox.Show("Excel file created , you can find the file " + "c:\\tmp\\test1.xlsx");
System.Diagnostics.Process.Start("c:\\tmp\\test1.xlsx");
// Close the Excel Application
excelApplication.Quit();
connection.Close();
//Release or clear the COM object
releaseObject(excelWorkBook);
releaseObject(excelApplication);
}
Thanks
Regards,
Jan Meeling
modified 19-Aug-19 7:40am.
|
|
|
|
|
Where is the code that transforms the Date fields?
|
|
|
|
|
Hi Richard,
I was trying that with no results.
Do yoy have a solution how to do this.
Thanks,
Regards,
Jan Meeling
|
|
|
|
|
|
jan Meeling wrote: I was trying that with no results. Trying what? Please show the code that saves, and formats, the Date field(s).
|
|
|
|
|
Did you try to set the cell format as DATE, not DateTime?
|
|
|
|
|
Hi Victor,
Thanks for your quick response.
Do you have the phrase How I have to implement.
Thanks
Regards,
Jan Meeling
|
|
|
|
|
Usually you don't include the password for the sa-account in the question. Usually we also frown on "SELECT *", and weirdly, you use a "using" clause for the connection but not for the disposable command.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi Bastard,
I have removed the password and this is only in a test enviroment,
And what do you mean with
Usually we also frown on "SELECT *", and weirdly, you use a "using" clause for the connection but not for the disposable command.
Thanks
Regards
Jan Meeling
|
|
|
|
|
jan Meeling wrote: Usually we also frown on "SELECT *", A select all, versus a select where you only select what you will use. You're now fetching more than expected and this may have an impact on speed.
jan Meeling wrote: and weirdly, you use a "using" clause for the connection but not for the disposable command. You put the connection in a using-block, but not the command. Any reason why?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi all,
I have it working know.
The solution is in the SQL string.
SELECT ID_BHV_Users, Voornaam , Achternaam , FORMAT (Geboorte_Datum, 'dd/MM/yyyy'), Porto_Nummer , Format (EHBO_Behaald, 'dd/MM/yyyy') , EHBO , BHV , Regiseur , Format ( Verlopen, 'dd/MM/yyyy') , Format (Laatste_herhaling, 'dd/MM/yyyy') , EHBO_nummer , verdieping , Ruimte , Email , Mobiel , Opmerking , Format (BHV_Behaald, 'dd/MM/yyyy') , Format (BHV_Verlopen, 'dd/MM/yyyy') , Format (Laatste_Herhaling_BHV, 'dd/MM/yyyy') , Ruisnaam , Format (Regisseur_Verlopen, 'dd/MM/yyyy') , Format (Regisseur_Behaald, 'dd/MM/yyyy') , Format (Regisseur_Herhaling, 'dd/MM/yyyy') , Active_no_yes FROM BHVUsers"
I use the format in the SQL string
You All thanks for putting me in the right direction.
Thanks
Jan Meeling
|
|
|
|
|
Well that is even worse than where you started from. Do not use formatted date strings but use proper date values and Date types. Also use proper parameterised queries to avoid SQL injection problems.
|
|
|
|
|
Hi Richard,
Thanks for reaction.
Can you give me the right way how to do is.
I now about SQL injection problems but this not connected to the internet and only in my test environment.
Thanks,
regards,
Jan Meeling
|
|
|
|
|
|
Hi all,
I have it working know.
The solution is in the SQL string.
SELECT ID_BHV_Users, Voornaam , Achternaam , FORMAT (Geboorte_Datum, 'dd/MM/yyyy'), Porto_Nummer , Format (EHBO_Behaald, 'dd/MM/yyyy') , EHBO , BHV , Regiseur , Format ( Verlopen, 'dd/MM/yyyy') , Format (Laatste_herhaling, 'dd/MM/yyyy') , EHBO_nummer , verdieping , Ruimte , Email , Mobiel , Opmerking , Format (BHV_Behaald, 'dd/MM/yyyy') , Format (BHV_Verlopen, 'dd/MM/yyyy') , Format (Laatste_Herhaling_BHV, 'dd/MM/yyyy') , Ruisnaam , Format (Regisseur_Verlopen, 'dd/MM/yyyy') , Format (Regisseur_Behaald, 'dd/MM/yyyy') , Format (Regisseur_Herhaling, 'dd/MM/yyyy') , Active_no_yes FROM BHVUsers"
I use the format in the SQL string
You All thanks for putting me in the right direction.
Thanks
Jan Meeling Smile | Wink |
|
|
|
|
|